问题 H: Snuke's Coloring 2-1
时间限制: 1 Sec 内存限制: 128 MB提交: 297 解决: 123
[ 提交][ 状态][ 讨论版][命题人: admin]
题目描述
There is a rectangle in the xy-plane, with its lower left corner at (0,0) and its upper right corner at (W,H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white.
Snuke plotted N points into the rectangle. The coordinate of the i-th (1≤i≤N) point was (xi,yi).
Then, he created an integer sequence a of length N, and for each 1≤i≤N, he painted some region within the rectangle black, as follows:
If ai=1, he painted the region satisfying x<xi within the rectangle.
If ai=2, he painted the region satisfying x>xi within the rectangle.
If ai=3, he painted the region satisfying y<yi within the rectangle.
If ai=4, he painted the region satisfying y>yi within the rectangle.
Find the area of the white region within the rectangle after he finished painting.
Constraints
1≤W,H≤100
1≤N≤100
0≤xi≤W (1≤i≤N)
0≤yi≤H (1≤i≤N)
W, H (21:32, added), xi and yi are integers.
ai (1≤i≤N) is 1,2,3 or 4.
Snuke plotted N points into the rectangle. The coordinate of the i-th (1≤i≤N) point was (xi,yi).
Then, he created an integer sequence a of length N, and for each 1≤i≤N, he painted some region within the rectangle black, as follows:
If ai=1, he painted the region satisfying x<xi within the rectangle.
If ai=2, he painted the region satisfying x>xi within the rectangle.
If ai=3, he painted the region satisfying y<yi within the rectangle.
If ai=4, he painted the region satisfying y>yi within the rectangle.
Find the area of the white region within the rectangle after he finished painting.
Constraints
1≤W,H≤100
1≤N≤100
0≤xi≤W (1≤i≤N)
0≤yi≤H (1≤i≤N)
W, H (21:32, added), xi and yi are integers.
ai (1≤i≤N) is 1,2,3 or 4.
输入
The input is given from Standard Input in the following format:
W H N
x1 y1 a1
x2 y2 a2
:
xN yN aN
W H N
x1 y1 a1
x2 y2 a2
:
xN yN aN
输出
Print the area of the white region within the rectangle after Snuke finished painting.
样例输入
5 4 2
2 1 1
3 3 4
样例输出
9
提示
The figure below shows the rectangle before Snuke starts painting.
First, as (x1,y1)=(2,1) and a1=1, he paints the region satisfying x<2 within the rectangle:
Then, as (x2,y2)=(3,3) and a2=4, he paints the region satisfying y>3 within the rectangle:
Now, the area of the white region within the rectangle is 9.
First, as (x1,y1)=(2,1) and a1=1, he paints the region satisfying x<2 within the rectangle:
Then, as (x2,y2)=(3,3) and a2=4, he paints the region satisfying y>3 within the rectangle:
Now, the area of the white region within the rectangle is 9.
题意:给一个点和四种操作方式,问最后操作结束之后,白色区域的面积是多少。
分析:一开始想开数组模拟然后求标记点,后来发现用不着,直接根据输入的数据不断缩小白色区域的范围即可,用x1,x2分别代表白色区域的上、下两边,用y1,y2分别代表左右两边。结果就很容易求了。
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<vector>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<deque>
#include<ctype.h>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<algorithm>
#define INF 0x3f3f3f3f
#define gcd(a,b) __gcd(a,b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define FAST_IO ios::sync_with_stdio(false)
const double PI = acos(-1.0);
const double eps = 1e-6;
const int MAX=1e5+10;
const int mod=1e9+7;
typedef long long ll;
using namespace std;
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll qpow(ll a,ll b){ll r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
inline ll inv1(ll b){return qpow(b,mod-2);}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll r=exgcd(b,a%b,y,x);y-=(a/b)*x;return r;}
inline ll read(){ll x=0,f=1;char c=getchar();for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;for(;isdigit(c);c=getchar()) x=x*10+c-'0';return x*f;}
struct node
{
int x,y,a;
}p[105];
int w,h,n;
int mp[105][105]={0};
int main()
{
int i,j,k;
int x1=0,y1=0,x2=0,y2=0;
scanf("%d%d%d",&w,&h,&n);
for(i=1;i<=n;i++)
scanf("%d%d%d",&p[i].x,&p[i].y,&p[i].a);
x1=w;
y1=h;
x2=y2=0;
for(i=1;i<=n;i++)
{
if(p[i].a==1)
x2=max(x2,p[i].x);
else if(p[i].a==2)
x1=min(x1,p[i].x);
else if(p[i].a==3)
y2=max(y2,p[i].y);
else if(p[i].a==4)
y1=min(y1,p[i].y);
}
//printf("%d %d %d %d\n",x1,x2,y1,y2);
if((x1-x2)>=0 && (y1-y2)>=0)
printf("%d\n",(x1-x2)*(y1-y2));
else
printf("0\n");
return 0;
}
Snuke's Coloring 2-1 是一道编程竞赛题目,主要考察参赛者的逻辑思维和算法应用能力。题目提供时间限制和内存限制,目前已有297次提交,123次成功解决。具体内容包括题目描述、输入输出格式、样例输入输出及解题提示。
528

被折叠的 条评论
为什么被折叠?



