Codeforces Round #203 (Div. 2)

A:超级大水题,不解释:

代码:

 1 #include<iostream>
 2 #include<algorithm>
 3 using namespace std;
 4 int a,b;
 5 int main()
 6 {
 7     int n,m,ma=0,mi=9999999,mb=9999999;
 8     cin>>n>>m;
 9     for(int i=0; i<n; i++)
10     {
11         cin>>a;
12         if(a>ma)ma=a;
13         if(a<mi)mi=a;
14     }
15     for(int i=0; i<m; i++)
16     {
17         cin>>b;
18         if(mb>b)mb=b;
19     }
20     if(mi*2>ma)ma=mi*2;
21     if(ma>=mb)cout<<"-1";
22     else cout<<ma;
23     return 0;
24 }
View Code

B:很简单,打个标记,dfs解决;

 1 #include<cstdio>
 2 #include<vector>
 3 #include<algorithm>
 4 #define maxn 100005
 5 using namespace std;
 6 vector<int>ve[maxn];
 7 int belong[maxn],to[maxn];
 8 bool vis[maxn],dead[maxn];
 9 void dfs(int x,int f)
10 {
11     if(to[x]==0||belong[to[x]]==1||dead[to[x]])return;
12     ve[f].push_back(to[x]);
13     dfs(to[x],f);
14 }
15 
16 int main()
17 {
18     int n;
19     scanf("%d",&n);
20     for(int i=1; i<=n; i++)scanf("%d",&belong[i]);
21     for(int i=1; i<=n; i++)
22     {
23         scanf("%d",&to[i]);
24         if(to[i]!=0)
25         {
26             if(vis[to[i]])
27                 dead[to[i]]=1;
28             else vis[to[i]]=1;
29         }
30     }
31     for(int i=1; i<=n; i++)
32     {
33         if(belong[i]==1)
34         {
35             ve[i].push_back(i);
36             dfs(i,i);
37         }
38     }
39     int ma=0,k;
40     for(int i=1; i<=n; i++)if(ve[i].size()>ma)
41         {
42             ma=ve[i].size();
43             k=i;
44         }
45     printf("%d\n",ma);
46     for(int i=ma-1; i>=0; i--)printf("%d ",ve[k][i]);
47     return 0;
48 }
View Code

C:很简单,排个序,然后按照规则输出就行;

 1 #include<cstdio>
 2 #include<algorithm>
 3 #define maxn 100005
 4 using namespace std;
 5 
 6 struct bomb
 7 {
 8     int x,y;
 9     bool operator<(const bomb &t)const
10     {
11         if(abs(x)==abs(t.x))return abs(y)<abs(t.y);
12         return abs(x)<abs(t.x);
13     }
14 } bo[maxn];
15 
16 int main()
17 {
18     int n,ans=0;
19     scanf("%d",&n);
20     for(int i=0; i<n; i++)
21     {
22         scanf("%d%d",&bo[i].x,&bo[i].y);
23         if(bo[i].x==0||bo[i].y==0)ans+=4;
24         else ans+=6;
25     }
26     sort(bo,bo+n);
27     printf("%d\n",ans);
28     for(int i=0; i<n; i++)
29     {
30         if(bo[i].x!=0)
31         {
32             printf("1 %d ",abs(bo[i].x));
33             puts(bo[i].x>0?"R":"L");
34         }
35         if(bo[i].y!=0)
36         {
37             printf("1 %d ",abs(bo[i].y));
38             puts(bo[i].y>0?"U":"D");
39         }
40         puts("2");
41         if(bo[i].x!=0)
42         {
43             printf("1 %d ",abs(bo[i].x));
44             puts(bo[i].x>0?"L":"R");
45         }
46         if(bo[i].y!=0)
47         {
48             printf("1 %d ",abs(bo[i].y));
49             puts(bo[i].y>0?"D":"U");
50         }
51         puts("3");
52     }
53     return 0;
54 }
View Code

 

posted @ 2013-10-15 18:14  Yours1103  阅读(233)  评论(0编辑  收藏  举报