水一发

http://codeforces.com/problemset/problem/602/B 最大的稳定子序列

 1 #include<iostream>
 2 using namespace std;
 3 #define MAX 100002
 4 struct P
 5 {
 6     int v,t;
 7 } p[MAX];
 8 int main()
 9 {
10     int n,tem;
11     cin>>n;
12     for(int i=0; i<n; i++)
13     {
14         p[i].v=0;
15         p[i].t=0;
16     }
17     cin>>p[0].v;
18     p[0].t=1;
19     int l=1;/// 不同元素个数
20     for(int i=1; i<n; ++i)
21     {
22         cin>>tem;
23         if(tem==p[l-1].v)
24             p[l-1].t++;///次数++
25         else
26         {
27             p[l].v=tem;
28             p[l].t++;
29             l++;
30         }
31     }
32 
33     int maxx=0; ///结果
34     struct P tt=p[0];  ///第一数
35     for(int i=1; i<l; i++)
36     {
37         int ans=0;
38         if(abs(p[i].v-tt.v)<=1)
39         {
40             int f=p[i].v;
41             ans+=p[i].t;
42             ans+=tt.t;
43             int flag=0;
44             while(p[i+1].v==tt.v||f==p[i+1].v)
45             {
46                 ans+=p[i+1].t;
47                 i++;
48                 flag=1;
49             }
50             if(flag)i--;
51             tt=p[i];
52            //  cout<<"---"<<ans<<endl;
53             maxx=max(maxx,ans);
54 
55         }
56     }
57     if(maxx==0)cout<<p[0].t<<endl;
58     else
59     cout<<maxx<<endl;
60     return 0;
61 }
View Code

 http://codeforces.com/problemset/problem/554/B 扫垃圾(水)

 1 #include<iostream>
 2 #include<map>
 3 using namespace std;
 4 map<string,int> mp;
 5 int main()
 6 {
 7     int n,maxx;
 8     string s;
 9     cin>>n;
10     maxx=0;
11     for(int i=0; i<n; i++)
12     {
13         cin>>s;
14         mp[s]++;
15         maxx=max(maxx,mp[s]);
16     }
17     cout<<maxx<<endl;
18     return 0;
19 }
View Code

 CSU 1783 聊天止于呵呵

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<string.h>
 4 #include<sstream>
 5 #include<map>
 6 using namespace std;
 7 struct P
 8 {
 9     string user,str;
10     int point;
11 } p[1002];
12 map<string,int> mp;
13 char cp(char c)
14 {
15     if(c>='0'&&c<='9')
16         return c;
17     if(c>='a'&&c<='z')
18         return c;
19     if(c>='A'&&c<='Z')
20         return c+' ';
21     return ' ';
22 }
23 int hh(string s)
24 {
25     if(s.length()&1||s.length()<4)return 0;
26     for(int i=0; i<s.length()-1; i+=2)
27         if(s[i]!='h'&&s[i+1]!='e')
28             return 0;
29     return 1;
30 }
31 int main()
32 {
33     char s[1002];
34     int ii=0;
35     while(cin.getline(s,1002))
36     {
37         string u="";
38         for(int i=0; i<4; i++)
39         {
40             u+=s[i];
41             s[i]=' ';
42         }
43         if(u[0]=='-')break;
44         if(u[0]>u[3])
45         {
46             char t=u[0];
47             u[0]=u[3];
48             u[3]=t;
49         }
50         for(int i=0; i<strlen(s); i++)
51             s[i]=cp(s[i]);
52         for(int i=0; i<ii; i++)
53             if(u==p[i].user)
54                 p[i].user="";
55         p[ii].user=u;
56         p[ii].str=s;
57         p[ii].point=ii;
58         ii++;
59     }
60     int cut=0;
61     int sum=0;
62     for(int i=0; i<ii; i++)
63         if(p[i].user!="")
64         {
65             cut++;
66             string sss;
67             for(istringstream sin(p[i].str); sin>>sss;)
68                 if(hh(sss))
69                 {
70                     sum+=1;
71                     break;
72                 }
73         }
74     int ans = (double)sum/cut*100+0.5;
75     cout<<ans<<"%"<<endl;
76     return 0;
77 }
View Code

 CSU 1779 错误的算法

 1 #include<iostream>
 2 #include<string.h>
 3 using namespace std;
 4 #define MAX 502
 5 int a[MAX][MAX];
 6 int main()
 7 {
 8     int n,m,i,j;
 9     int Case=1;
10     while(scanf("%d%d",&n,&m)!=EOF)
11     {
12         memset(a,0,sizeof(a));
13         for(i=0; i<n; i++)
14         {
15             for(j=0; j<m; j++)
16             {
17                 scanf("%d",&a[i][j]);
18                 a[i][m]+=a[i][j];
19                 a[n][j]+=a[i][j];
20             }
21         }
22         int eans=0;
23         int fm=0;
24         int x=-1,y=-1;
25         for(i=0; i<n; i++)
26             if(fm<a[i][m])
27             {
28                 fm=a[i][m];
29                 x=i;
30             }
31         eans+=fm;
32         fm=0;
33         for(i=0; i<m; i++)
34             if(fm<a[n][i])
35             {
36                 fm=a[n][i];
37                 y=i;
38             }
39         eans+=fm;
40         eans-=a[x][y];
41         int ans = 0;
42         for(i=0; i<n; i++)
43             for(j=0; j<m; j++)
44                 ans= max(ans,a[i][m]+a[n][j]-a[i][j]);
45 
46         if(eans==ans)
47             cout<<"Case "<<Case<<": Weak"<<endl;
48         else
49             cout<<"Case "<<Case<<": Strong"<<endl;
50         Case++;
51     }
52     return 0;
53 }
View Code

 CSU 1785 又一道简单题

 1 #include<iostream>
 2 using namespace std;
 3 int main()
 4 {
 5     int T,i;
 6     scanf("%d",&T);
 7     for(int k=1 ; k <= T ; k++)
 8     {
 9         int n;
10         scanf("%d",&n);
11         int ans  = 0;
12         for(i=32;i<100;i++)
13         {
14             int x = i*i;
15             if( n == x) continue ;
16             if( x/10 == n/10 )
17             ans += 1;
18             if( x%1000 == n%1000)
19             ans += 1;
20             if( x/100*10+x%10 == n/100*10+n%10 )
21             ans += 1;
22             if( x/1000*100+x%100 == n/1000*100+n%100)
23             ans += 1;
24         }
25         cout<<"Case "<<k<<": "<<ans<<endl;
26     }
27     return 0;
28 }
View Code

 codeforces 785B 区间问题 (最晚的开始,最早的结束)

 1 #include<iostream>
 2 #include<cstdio>
 3 using namespace std;
 4 int main()
 5 {
 6     int n,m;
 7     scanf("%d",&n);
 8     int xs=0,xe=0x7fffffff;
 9     int ps=0,pe=0x7fffffff;
10     int x,y;
11     for(int i = 0; i < n; ++i)
12     {
13         scanf("%d%d",&x,&y);
14         xs=max(xs,x);
15         xe=min(xe,y);
16     }
17     scanf("%d",&m);
18     for(int j = 0; j < m; ++j)
19     {
20         scanf("%d%d",&x,&y);
21         ps=max(ps,x);
22         pe=min(pe,y);
23     }
24     int ans1 = 0,ans2 = 0;
25     if( ps > xe)
26         ans1 = ps - xe;
27     if( xs > pe)
28         ans2 = xs - pe;
29     cout<<max(ans1,ans2)<<endl;
30     return 0;
31 }
View Code

 VIJOS 卡布列克圆舞曲 (对数分解取最大和最小相减,形成规律数列

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<string.h>
 4 #include<algorithm>
 5 #include<map>
 6 #include<queue>
 7 #include<cmath>
 8 using namespace std;
 9 #define ll long long
10 #define N 1004
11 ll len(ll n)
12 {
13     ll l = 0;
14     while(n > 0)
15     {
16         n /= 10;
17         ++l;
18     }
19     return l;
20 }
21 ll getMaxOrMin(ll n,ll flag)//得到一个数将其数字重排的最大值和最小值
22 {
23     ll a[len(n)] = {0};
24     ll j = 0;
25     ll nn=n;
26     for(ll i = 0; i < len(n); ++i)
27     {
28         a[j] = nn % 10;
29         nn /= 10;
30         ++j;
31     }
32     sort(a,a+j);
33     ll ans = 0;
34     if(!flag)
35     {
36         ans = a[0];
37         for(ll i = 1; i < len(n); ++i)
38             ans = ans * 10 + a[i];
39     }
40     else
41     {
42         ans = a[len(n)-1];
43         for(ll i = len(n)-2; i>=0; i--)
44             ans = ans * 10 + a[i];
45     }
46     return ans;
47 }
48 
49 ll a[N];
50 
51 int main()
52 {
53     ll n;
54     while( cin>>n )
55     {
56         ll j = 1,flag = 0;
57         a[0] = n;
58         while(1)
59         {
60             a[j] = getMaxOrMin(n,1) - getMaxOrMin(n,0);
61 
62             for(ll i = j-1; i >= 0; i--)
63                 if(a[j] == a[i])
64                 {
65                     flag=i+1;
66                     break;
67                 }
68             if(flag)
69             {
70                 for(ll i = flag-1; i < j-1; i++)
71                     cout<<a[i]<<" ";
72                 cout<<a[j-1]<<endl;
73                 break;
74             }
75             n = a[j];
76             j++;
77         }
78     }
79     return 0;
80 }
View Code

 山东第六届ACM J 题

问题:给出男女数量,1-1匹配,分成相同的11组,各组男女对数相同,若给出的男女数量满足-》YES 否则,NO

 1 #include<iostream>
 2 #include<string.h>
 3 #include<algorithm>
 4 using namespace std;
 5 int main()
 6 {
 7     string s,s1;
 8     int t;
 9     cin>>t;
10     while(t--)
11     {
12         int flag = 0,x = 0;
13         cin>>s>>s1;
14         if(s[0]=='0'&&s1[0]=='0'){cout<<"NO"<<endl;continue;}
15         if(s.length()==s1.length())
16         {
17 
18             int i = 0;
19             for(i = 0; i < s.length(); ++i)
20                 if(s[i]!=s1[i])break;
21             if(i==s.length())
22             {
23                 for(int k = 0; k < s.length(); ++k)
24                 {
25                     x = (x*10+(s[k]-'0'))%11;
26                 }
27                 if(x==0)
28                     flag=1;
29             }
30         }
31         if(flag)
32             cout<<"YES"<<endl;
33         else cout<<"NO"<<endl;
34     }
35     return 0;
36 }
View Code

 

posted @ 2017-04-24 22:44  马丁黄瓜啊  阅读(277)  评论(0编辑  收藏  举报