usaco 洛谷 P2694 接金币 题解

题目描述

在二维坐标系里,有N个金币,编号0至N-1。初始时,第i个金币的坐标是(Xi,Yi)。所有的金币每秒向下垂直下降一个单位高度,例如有个金币当前坐标是(xf, yf),那么t秒后金币所在的位置就是(xf, yf-t)。初始时,FJ在(0,0)坐标处,FJ每秒只能向左移动一个单位距离或者向右移动一个单位距离,当然FJ也可以不移动。如果在某个时刻某个金币和FJ所在的位置重合,那么FJ就能接住这个金币。FJ能否把所有的金币都接住?如果行输出Abletocatch,否则输出Notabletocatch。

输入输出格式

输入格式:

 

多组测试数据。

第一行,一个整数G,表示有G组测试数据。1 <= G <= 5。

每组测试数据格式如下:

第一行,一个整数N。 1 <= N <= 50。

接下来有N行,第i行两个整数表示Xi、Yi。

  -1000<=Xi<=1000。0<=Yi<=1000。

 

输出格式:

 

共G行,每行输出Abletocatch或Notabletocatch。

 

输入输出样例

输入样例#1:
5
3
-1 1
1 3
0 4
1
-3 2
3
-1 1
1 2
0 4
3
0 9
-1 1
1 3
8
70 141
-108 299
52 402
-70 280
84 28
-29 363
66 427
-33 232
输出样例#1:
Abletocatch
Notabletocatch
Notabletocatch
Abletocatch
Notabletocatch
————————————————————————————————————我是分割线——————————————————————————————————————————
纯模拟。水题目。
 1 /*
 2     Problem:
 3     OJ:
 4     User:    S.B.S.
 5     Time:
 6     Memory:
 7     Length:
 8 */
 9 #include<iostream>
10 #include<cstdio>
11 #include<cstring>
12 #include<cmath>
13 #include<algorithm>
14 #include<queue>
15 #include<cstdlib>
16 #include<iomanip>
17 #include<cassert>
18 #include<climits>
19 #include<functional>
20 #include<bitset>
21 #include<vector>
22 #include<list>
23 #define F(i,j,k) for(int i=j;i<=k;++i)
24 #define M(a,b) memset(a,b,sizeof(a))
25 #define FF(i,j,k) for(int i=j;i>=k;i--)
26 #define maxn 10001
27 #define inf 0x3f3f3f3f
28 #define maxm 4001
29 #define mod 998244353
30 //#define LOCAL
31 using namespace std;
32 int read(){
33     int x=0,f=1;char ch=getchar();
34     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
35     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
36     return x*f;
37 }
38 int n,m;
39 int data[1001];
40 int main(int argc,const char *argv)
41 {
42     std::ios::sync_with_stdio(false);//cout<<setiosflags(ios::fixed)<<setprecision(1)<<y;
43     #ifdef LOCAL
44     freopen("data.in","r",stdin);
45     freopen("data.out","w",stdout);
46     #endif
47     int g;cin>>g;
48     while(g--){
49         cin>>n;bool flag=false;
50         F(i,1,1000) data[i]=-inf;
51         F(i,1,n){
52             int x,y;
53             cin>>x>>y;
54             if(data[y]!=-inf&&x!=data[y]){flag=true;}
55             if(data[y]!=-inf) continue;
56             data[y]=x;
57         }
58         if(flag==true){cout<<"Notabletocatch"<<endl;continue;}
59         int pos=0,pre=0;flag=false;data[0]=0;
60 //        F(i,1,n) cout<<data[i]<<" "<<endl;
61         F(i,1,1000){
62             if(data[i]==-inf) continue;
63             int time=abs(i-pre);
64 //            cout<<i<<" "<<pre<<" "<<data[i]<<" "<<data[pre]<<endl;
65             if(abs(data[i]-data[pre])>time){flag=true;break;}
66             pre=i;
67         }
68         if(flag==true) cout<<"Notabletocatch"<<endl;
69         else cout<<"Abletocatch"<<endl;
70     }
71     return 0;
72 }
p2964

 

posted @ 2016-10-24 19:43  SBSOI  阅读(575)  评论(0编辑  收藏  举报