Skip to main content
  1. Posts/

codeforces 522 A. Vanya and Table

Note: This article is available in Chinese only. 本文暂无英文版本。 View original

http://codeforces.com/problemset/problem/552/A 题意:一个100*100的网格。然后给n个矩形。每个格子中填上包含这个格子的矩形的个数。最后问所有格子的和。 思路:树状数组搞得…然而..直接求所有矩形面积的和就可以啊喂。。o(n)。。。111qqz你个炒鸡大菜鸡。

  1/* ***********************************************
  2Author :111qqz
  3Created Time :2015年12月14日 星期一 14时01分14秒
  4File Name :code/cf/problem/552A.cpp
  5************************************************ */
  6
  7#include <cstdio>
  8#include <cstring>
  9#include <iostream>
 10#include <algorithm>
 11#include <vector>
 12#include <queue>
 13#include <set>
 14#include <map>
 15#include <string>
 16#include <cmath>
 17#include <cstdlib>
 18#include <ctime>
 19#define fst first
 20#define sec second
 21#define lson l,m,rt<<1
 22#define rson m+1,r,rt<<1|1
 23#define ms(a,x) memset(a,x,sizeof(a))
 24typedef long long LL;
 25#define pi pair < int ,int >
 26#define MP make_pair
 27
 28using namespace std;
 29const double eps = 1E-8;
 30const int dx4[4]={1,0,0,-1};
 31const int dy4[4]={0,-1,1,0};
 32const int inf = 0x3f3f3f3f;
 33const int N=1E2+7;
 34int n;
 35int c[N][N];
 36struct Point
 37{
 38    int x1,y1,x2,y2;
 39
 40    void input()
 41    {
 42	scanf("%d %d",&x1,&y1);
 43	scanf("%d %d",&x2,&y2);
 44    }
 45}p[N];
 46
 47int lowbit( int x)
 48{
 49    return x&(-x);
 50}
 51void update( int x,int y,int delta)
 52{
 53    for ( int i = x ; i <= 105 ; i += lowbit(i))
 54    {
 55	for ( int j =  y ; j <= 105 ; j +=lowbit(j))
 56	{
 57	    c[i][j] +=delta;
 58	}
 59    }
 60}
 61
 62int sum ( int x,int y)
 63{
 64    int res = 0 ;
 65    for ( int i =  x;  i>= 1 ; i-=lowbit(i))
 66    {
 67	for ( int j = y ; j >= 1 ; j-=lowbit(j))
 68	{
 69	    res += c[i][j];
 70	   // cout<<"res:"<<res<<endl;
 71	}
 72    }
 73
 74    return res;
 75}
 76int main()
 77{
 78	#ifndef  ONLINE_JUDGE
 79	freopen("code/in.txt","r",stdin);
 80  #endif
 81	ms(c,0);
 82	cin>>n;
 83	for ( int i = 0 ; i < n; i++) p[i].input();
 84
 85//	puts("aahhhhhh");
 86	for ( int i = 0 ; i <n ; i++)
 87	{
 88	    update(p[i].x2+1,p[i].y2+1,1);
 89	   // cout<<"www?"<<endl;
 90	    update(p[i].x2+1,p[i].y1,-1);
 91	    update(p[i].x1,p[i].y2+1,-1);
 92	    update(p[i].x1,p[i].y1,1);
 93	//    puts("yyyyepppppp");
 94	}
 95	int ans = 0;
 96	for ( int i = 1 ; i <= 101 ; i ++)
 97	    for ( int j = 1 ; j <= 101;  j++)
 98
 99		ans += sum(i,j);
100	cout<<ans<<endl;
101
102  #ifndef ONLINE_JUDGE
103  fclose(stdin);
104  #endif
105    return 0;
106}

Related

codeforces 505 B. Mr. Kitayuta's Colorful Graph

·1 min
http://codeforces.com/contest/505/problem/B 题意;给一个图,边有颜色。给q个查询,每个查询一对点x,y。问只经过某种颜色的边使得x能到y颜色数目。 思路:存颜色的时候卡了下。。本来打算开一个二维的set用来存颜色。。。没想明白。。后来发现。。还是用vecotr就好啊。。。多开一维度vector。。或者。。vector 用 pair 都是可以的。。。因为颜色数不多。。可以暴力枚举每种颜色做一遍dfs 看只走有这条颜色的边x能否到y。。

codeforces #327 A. Wizards' Duel

·1 min
题意:一个长度为l的走廊。两个人站在两端点。互相向对方发射某种魔法。A的魔法速度为p米/秒,B的魔法速度为q米/s,魔法相遇以后会反射。反射会发射人那里会再次发射。问两种魔法第二次相遇的时候距离A的距离。 思路:由于每种魔法的速度保持肯定不变。。所以不管第几次相遇。相遇点都是同一个。。。ans=p*(p+q)/l;