# Codeforces Round #252 (Div. 2)

A. Valera and Antique Items

 1 #include<iostream>
2 #include<cstdio>
3 #include<algorithm>
4 #define maxn 1000
5 using namespace std;
6 int ans[maxn],h,x,k;
7 int main()
8 {
9     int n,v;
10     scanf("%d%d",&n,&v);
11     for(int i=1;i<=n;i++)
12     {
13         scanf("%d",&k);
14         int flag=0;
15         for(int j=1;j<=k;j++)
16         {
17             scanf("%d",&x);
18             if(x<v && flag==0)ans[++h]=i,flag=1;
19         }
20     }
21     printf("%d\n",h);
22     for(int i=1;i<=h;i++)printf("%d ",ans[i]);
23     return 0;
24 }
View Code

B. Valera and Fruits

 1 #include<cstdio>
2 #include<algorithm>
3 #define maxn 10000
4 using namespace std;
5 struct T
6 {
7     int x;int y;
8 }a[maxn];
9 int cmp(T a ,T b)
10 {
11     return a.x<b.x;
12 }
13 int day[maxn];
14 int main()
15 {
16     int n,v;
17     scanf("%d%d",&n,&v);
18     for(int i=1;i<=n;i++)
19     {
20         scanf("%d%d",&a[i].x,&a[i].y);
21         day[a[i].x]+=a[i].y;
22     }
23     int ans=0;
24     for(int i=1;i<=3009;i++)
25     {
26         if(v<=day[i-1])
27         {
28             ans+=v;
29         }
30         else
31         {
32             ans+=day[i-1];
33             int u=v-day[i-1];
34             if(day[i]>=u)
35             {
36                 day[i]-=u;
37                 ans+=u;
38             }
39             else
40             {
41                 ans+=day[i];
42                 day[i]=0;
43             }
44         }
45     }
46     printf("%d\n",ans);
47     return 0;
48 }
View Code

C. Valera and Tubes

 1 #include<cstdio>
2 #include<iostream>
3 using namespace std;
4 int dir=1,x=1,y=0,n,m,r;
5 int next()
6 {
7     if(dir==1)
8     {
9         if(y==m)x++,dir--;else
10         y++;
11     }
12     else
13     {
14         if(y==1)x++,dir++;else y--;
15     }
16     printf("%d %d ",x,y);
17 }
18 int main()
19 {
20     scanf("%d%d%d",&n,&m,&r);
21     for(int i=1;i<r;i++)
22     {
23         printf("2 ");next();next();
24         puts("");
25     }
26     printf("%d ",n*m-(r-1)*2);
27     for(int i=1;i<=n*m-(r-1)*2;i++)next();
28     return 0;
29 }
View Code

D. Valera and Swaps

 1 #include<iostream>
2 #include<cstdio>
3 #include<cstring>
4 #define maxn 10000
5 using namespace std;
6 int visit[maxn],p[maxn],kk;
7 int dfs(int k,int ini)
8 {
9     if(k!=ini && k-ini<=kk-ini)kk=k;
10     if(visit[k]==1)return k-1;
11     visit[k]=1;
12     return dfs(p[k],ini);
13 }
14 int main()
15 {
16     int n,ans=0,k;
17     scanf("%d",&n);
18     for(int i=1;i<=n;i++)
19     {
20         scanf("%d",&p[i]);
21     }
22     scanf("%d",&k);
23     int cir=0;
24     for(int i=1;i<=n;i++)
25     {
26         if(!visit[i])dfs(i,i),cir++;
27     }
28     if(n-cir==k)
29     {
30         puts("0");
31     }
33     {
34         printf("%d\n",k-n+cir);
35         for(int i=1;i<=k-n+cir;i++)
36         {
37             memset(visit,0,sizeof(visit));
38             dfs(1,1);
39             int j;
40             for(j=1;j<=n;j++)
41             {
42                 if(!visit[j])break;
43             }
44             swap(p[1],p[j]);
45             printf("1 %d ",j);
46         }
47     }
48     else
49     {
50         printf("%d\n",n-k-cir);
51         for(int i=1;i<=n-k-cir;i++)
52         {
53             memset(visit,0,sizeof(visit));
54             int ans=0,j;
55             for(j=1;j<=n;j++)
56             {
57                 kk=0x3f3f3f3f;
58                 if(p[j]!=j)
59                 {
60                     int kk=0x3f3f3f3f;
61                     dfs(j,j);
62                     break;
63                 }
64             }
65             swap(p[j],p[kk]);
66             printf("%d %d ",j,kk);
67         }
68     }
69     return 0;
70 }
View Code

posted @ 2015-03-06 14:54  philippica  阅读(113)  评论(0编辑  收藏  举报