24h購物| | PChome| 登入
2012-11-04 17:24:29| 人氣458| 回應0 | 上一篇 | 下一篇

[ACM-ICPC] 5698 - Draw a Mess

推薦 0 收藏 0 轉貼0 訂閱站台

It's graduated season, every students should leave something on the wall, so....they draw a lot of geometry shape with different color.

When teacher come to see what happened, without getting angry, he was surprised by the talented achievement made by students. He found the wall full of color have a post-modern style so he want to have an in-depth research on it.

To simplify the problem, we divide the wall into n*m ( 1$ le$n$ le$200, 1$ le$m$ le$50000) pixels, and we have got the order of coming students who drawing on the wall. We found that all students draw four kinds of geometry shapes in total that is Diamond, Circle, Rectangle and Triangle. When a student draw a shape in pixel (i, j) with color c ( 1$ le$c$ le$9), no matter it is covered before, it will be covered by color c.

There are q ( 1$ le$q$ le$50000) students who have make a drawing one by one. And after q operation we want to know the amount of pixels covered by each color.

Input 

There are multiple test cases.

In the first line of each test case contains three integers n, m, q. The next q lines each line contains a string at first indicating the geometry shape:

  • Circle: given xc, yc, r, c, and you should cover the pixels (x, y) which satisfied inequality (x - xc)2 + (y - yc)2$ le$r2 with color c;
  • Diamond: given xc, yc, r, c, and you should cover the pixels (x, y) which satisfied inequality | x - xc| + | y - yc|$ le$r with color c;
  • Rectangle: given xc, yc, l, w, c, and you should cover the pixels (x, y) which satisfied xc$ le$x$ le$xc + l - 1, yc$ le$y$ le$yc + w - 1 with color c;
  • Triangle: given xc, yc, w, c, W is the bottom length and is odd, the pixel (xc, yc) is the middle of the bottom. We define this triangle is isosceles and the height of this triangle is (w + 1)/2, you should cover the correspond pixels with color c;


Note: all shape should not draw out of the n*m wall! You can get more details from the sample and hint. (0$ le$xc, x$ le$n - 1, 0$ le$yc, y$ le$m - 1)

Output 

For each test case you should output nine integers indicating the amount of pixels covered by each color.


Hint: The final distribution of different colors:


00000000
03300000
03310000
00111000
00022240
00002444
00004444
00000444

Sample Input 

 
8 8 4
Diamond 3 3 1 1
Triangle 4 4 3 2
Rectangle 1 1 2 2 3
Circle 6 6 2 4

Sample Output 

 
4 4 4 11 0 0 0 0 0



調整心理的模擬題。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cstdlib>
#include<map>
#define mem(x) memset(x,0,sizeof(x))
using namespace std;

typedef long long ll;
char g[200][50000];
int main(){
long long n, m, q, i, j, k;
while(scanf("%lld %lld %lld", &n, &m, &q) == 3) {
for(i = 0; i < n; i++)
for(j = 0; j < m; j++)
g[i][j] = 0;
char cmd[100];
long long x, y, r, c, l, w, W;
while(q--) {
scanf("%s", cmd);
if(!strcmp(cmd, "Circle")) {
scanf("%lld %lld %lld %lld", &x, &y, &r, &c);
for(i = x-r; i <= x+r; i++) {
for(j = y-r; j <= y+r; j++) {
if(i < 0 || j < 0 || i >= n || j >= m)
continue;
if((i-x)*(i-x)+(j-y)*(j-y) > r*r)
continue;
g[i][j] = c;
}
}
} else if(!strcmp(cmd, "Diamond")) {
scanf("%lld %lld %lld %lld", &x, &y, &r, &c);
for(i = x-r; i <= x+r; i++) {
for(j = y-r; j <= y+r; j++) {
if(i < 0 || j < 0 || i >= n || j >= m)
continue;
if(abs(i-x)+abs(j-y) > r)
continue;
g[i][j] = c;
}
}
} else if(!strcmp(cmd, "Rectangle")) {
scanf("%lld %lld %lld %lld %lld", &x, &y, &l, &w, &c);
for(i = x; i < x+l; i++) {
for(j = y; j < y+w; j++) {
if(i < 0 || j < 0 || i >= n || j >= m)
continue;
g[i][j] = c;
}
}
} else if(!strcmp(cmd, "Triangle")) {
scanf("%lld %lld %lld %lld", &x, &y, &w, &c);
int tw = w;
for(i = x; i <= x+(tw+1)/2+52; i++, w-=2) {
for(j = y-(w+1)/2+1; j <= y+(w+1)/2-1; j++) {
if(i < 0 || j < 0 || i >= n || j >= m)
continue;
g[i][j] = c;
}
}
}
}
int cnt[10] = {};
for(i = 0; i < n; i++)
for(j = 0; j < m; j++)
cnt[g[i][j]]++;
for(i = 1; i < 10; i++) {
if(i != 1)
printf(" ");
printf("%d", cnt[i]);
}
puts("");
}
return 0;
}

台長: Morris
人氣(458) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[ACM-ICPC][排容、逆元] 5701 - The Boss on Mars
此分類上一篇:[ACM-ICPC] 5696 - Hexadecimal View

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文