Codeforces Round #264 (Div. 2)

A. Caisa and Sugar

题意:你有s美元,有n样东西,找钱的零钱会换为糖,1美分=1糖,只能买一样东西的一个,求最多获得多少个糖果

题解:模拟即可。因为c++语法问题fst了。。。

        论掌握一门语言的重要性。。。

代码:

 1 #include<cstdio>
 2 #include<cstdlib>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<algorithm>
 6 #include<iostream>
 7 #include<vector>
 8 #include<map>
 9 #include<set>
10 #include<queue>
11 #include<string>
12 #define inf 1000000000
13 #define maxn 500+100
14 #define maxm 500+100
15 #define eps 1e-10
16 #define ll long long
17 #define pa pair<int,int>
18 using namespace std;
19 inline int read()
20 {
21     int x=0,f=1;char ch=getchar();
22     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
23     while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
24     return x*f;
25 }
26 int main()
27 {
28     int n=read(),m=read();
29     int x,y,ans=-1;
30     for(int i=1;i<=n;i++)
31      {
32          x=read();y=read();
33          if(100*x+y<=100*m)
34           {
35               if(y)ans=max(ans,100-y);else ans=max(ans,0);
36           }
37      }
38     printf("%d\n",ans); 
39     return 0;
40 }
View Code

B. Caisa and Pylons

题意:给你一个数列,有n+1个数,a[0]=0,将这个序列差分,要保持前缀和时刻都非负,花费1可以使前缀和+1,求最小花费

题解:直接模拟即可,按差分来。。。脑洞好大。。。

        稍想一下就知道直接输出max即可。。。

代码:

 1 #include<cstdio>
 2 #include<cstdlib>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<algorithm>
 6 #include<iostream>
 7 #include<vector>
 8 #include<map>
 9 #include<set>
10 #include<queue>
11 #include<string>
12 #define inf 1000000000
13 #define maxn 100000+100
14 #define maxm 500+100
15 #define eps 1e-10
16 #define ll long long
17 #define pa pair<int,int>
18 using namespace std;
19 inline ll read()
20 {
21     int x=0,f=1;char ch=getchar();
22     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
23     while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
24     return x*f;
25 }
26 ll n,sum=0,ans=0,a[maxn];
27 int main()
28 {
29     n=read();
30     for(int i=1;i<=n;i++)a[i]=read();
31     for(int i=0;i<n;i++)a[i]=a[i]-a[i+1];
32     for(int i=0;i<n;i++)
33      {
34          sum+=a[i];
35          if(sum<0){ans+=-sum;sum=0;}
36      }
37     cout<<ans<<endl;
38     return 0;
39 }
View Code

C. Gargari and Bishops

题意:n*n矩阵,n<=2000,你可以选两个点,使得与这两个点处于同一条对角线上的所有数的和最大,并且这两个点所处的对角线不会相交。

题解:直接暴力枚举即可。。。因为选出的两个点对角线不会相交,所以肯定是黑白染色只后黑白各一个。分别取最大即可。

        考场上没看见最后一个条件,就弃疗了。。。

        论看全题目的重要性。。。

代码:

 1 #include<cstdio>
 2 #include<cstdlib>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<algorithm>
 6 #include<iostream>
 7 #include<vector>
 8 #include<map>
 9 #include<set>
10 #include<queue>
11 #include<string>
12 #define inf 1000000000
13 #define maxn 2000+10
14 #define maxm 500+100
15 #define eps 1e-10
16 #define ll long long
17 #define pa pair<int,int>
18 #define for0(i,n) for(int i=0;i<=n;i++)
19 #define for1(i,n) for(int i=1;i<=n;i++)
20 using namespace std;
21 inline ll read()
22 {
23     int x=0,f=1;char ch=getchar();
24     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
25     while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
26     return x*f;
27 }
28 ll a[maxn<<1],b[maxn<<1],c[maxn][maxn];
29 int main()
30 {
31     freopen("input.txt","r",stdin);
32     freopen("output.txt","w",stdout);
33     int n=read();
34     for1(i,n)
35      for1(j,n)
36       {
37           ll x=read();
38           a[i+j]+=x;b[i-j+n]+=x;
39           c[i][j]=x;
40       }
41     ll mx1=-1,mx2=-1,x1,y1,x2,y2,t;
42     for1(i,n)
43      for1(j,n)
44           if((i+j)&1)
45            {
46                t=a[i+j]+b[i-j+n]-c[i][j];
47             if(t>mx1)
48              {
49                  mx1=t;x1=i;y1=j;
50              }
51            } 
52           else 
53            {
54                t=a[i+j]+b[i-j+n]-c[i][j];
55             if(t>mx2)
56              {
57                  mx2=t;x2=i;y2=j;
58              }
59            }
60     cout<<mx1+mx2<<endl;
61     cout<<x1<<' '<<y1<<' '<<x2<<' '<<y2<<endl;
62     //printf("%d %d %d %d",x1,y1,x2,y2);    
63     return 0;
64 }
View Code

 D. Gargari and Permutations

题意:求2-5个数列的最长公共子序列。

题解:如果 j 在每个序列里都出现在 i 后面,则连边i-j,然后求最长路即可。

           巧妙的转化。

代码:

 

 1 #include<cstdio>
 2 #include<cstdlib>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<algorithm>
 6 #include<iostream>
 7 #include<vector>
 8 #include<map>
 9 #include<set>
10 #include<queue>
11 #include<string>
12 #define inf 1000000000
13 #define maxn 1000000
14 #define maxm 10
15 #define eps 1e-10
16 #define ll long long
17 #define pa pair<int,int>
18 #define for0(i,n) for(int i=0;i<=n;i++)
19 #define for1(i,n) for(int i=1;i<=n;i++)
20 using namespace std;
21 inline int read()
22 {
23     int x=0,f=1;char ch=getchar();
24     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
25     while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
26     return x*f;
27 }
28 struct edge{int go,next;}e[maxn];
29 int n,m,tot,d[maxn],a[maxm][maxn],head[maxn],inp[maxn],q[maxn];
30 void insert(int x,int y)
31 {
32     e[++tot].go=y;e[tot].next=head[x];head[x]=tot;
33 }
34 bool check(int x,int y)
35 {
36     for1(i,m)if(a[i][x]>a[i][y])return 0;
37     return 1;
38 }
39 int main()
40 {
41     freopen("input.txt","r",stdin);
42     freopen("output.txt","w",stdout);
43     n=read();m=read();
44     int x,y;
45     for1(i,m)for1(j,n) 
46      {
47          x=read();
48          a[i][x]=j;
49      }
50     for1(i,n)for1(j,n)if(i!=j&&check(i,j))insert(i,j),inp[j]++;
51     int l=0,r=0;
52     for1(i,n)d[i]=1;
53     for1(i,n)if(!inp[i])q[++r]=i;
54     while(l<r)
55     {
56         x=q[++l];
57         for(int i=head[x];i;i=e[i].next)
58          {
59              inp[y=e[i].go]--;
60              if(!inp[y])q[++r]=y;
61              d[y]=max(d[y],d[x]+1);
62          }
63     }
64     int ans=0;
65     for1(i,n)ans=max(ans,d[i]);
66     printf("%d\n",ans);
67     return 0;
68 }
View Code

 

posted @ 2014-08-30 18:58  ZYF-ZYF  Views(217)  Comments(0Edit  收藏  举报