2014/4/6长沙多校第六次(浙大校赛)

A:水水更健康

 1 /*
 2 zoj3767
 3 这道题目,水水更健康,囧
 4 */
 5 #include <iostream>
 6 #include <cmath>
 7 #include <algorithm>
 8 #include <string.h>
 9 #include <stdio.h>
10 #include <set>
11 #include <stack>
12 #include <vector>
13 #define maxn 50
14 #define L 13
15 using namespace std;
16 int T;
17 int main(){
18     scanf("%d",&T);
19     for(int i=0;i<T;i++){
20         int n,tot,add=0;
21         scanf("%d%d",&n,&tot);
22         for(int i=0;i<n;i++){
23             int x;
24             scanf("%d",&x);
25             add+=x;
26         }
27         if (add<=tot) printf("Safe\n");
28         else printf("Warning\n");
29     }
30     return 0;
31 }
View Code

B:数的拆分

 1 /*
 2 zoj3768
 3 定义 f(x)=1+2+3...+x=(1+x)x/2
 4 将一个数N,将这个数拆分成N=f(x1)+f(x2)..f(xi),使xi的个数尽可能的小。xi之间是可以重复的。
 5 1<=N<=987654321
 6 分析:
 7 看了网上别人过的代码,好像这个数量一定小于等于3,为神马?o(╯□╰)o
 8 如果是这样的话,分类讨论就可以了。
 9 注意xi的范围,先打表,有利于快速查找。
10 */
11 #include <iostream>
12 #include <cmath>
13 #include <algorithm>
14 #include <string.h>
15 #include <stdio.h>
16 #include <set>
17 #include <stack>
18 #include <vector>
19 #define maxn 15720
20 using namespace std;
21 int C[maxn];
22 void init(){
23     int T=0;
24     for(int i=1;i<maxn;i++){
25         T+=i;
26         C[i]=T;
27     }
28     return ;
29 }
30 int find(int k){
31     int L=1,R=maxn-1;
32     while(L<R){
33         int M=(L+R+1)/2;
34         if (k<C[M]) R=M-1;else L=M;
35     }
36     if (C[L]==k) return L;else return -1;
37 }
38 bool solve(int n){//将n拆分成两个数
39     int nn=n/2;
40     for(int i=1;i<maxn;i++){
41         if (n-C[i]<=0) return false;
42         if (find(n-C[i])!=-1) {
43             printf("%d %d",i,find(n-C[i]));
44             return true;
45         }
46     }
47     return false;
48 }
49 int T,N;
50 int main(){
51     init();
52     scanf("%d",&T);
53     for(int i=0;i<T;i++){
54         scanf("%d",&N);
55         int k=find(N);
56         if (k!=-1){//拆分成一个数
57             printf("%d\n",k);
58             continue;
59         }
60         if (solve(N)) {
61             printf("\n");
62             continue;
63         }
64 //        int nn=N/3;
65         for(int i=1;i<maxn;i++){
66             if (N-C[i]<=0) break;
67             if (solve(N-C[i])) {
68                 printf(" %d\n",i);
69                 break;
70             }
71         }
72     }
73     return 0;
74 }
View Code

C:

D:

E:

F:

G:

H:理解题意(o(╯□╰)o)

 1 /*
 2 zoj3775
 3 这道题目,难点是读懂题目,囧
 4 */
 5 #include <iostream>
 6 #include <cmath>
 7 #include <algorithm>
 8 #include <string.h>
 9 #include <stdio.h>
10 #include <set>
11 #include <stack>
12 #include <vector>
13 #define maxn 510
14 #define L 13
15 using namespace std;
16 char ss[]="Hello, world!";
17 char s[maxn];
18 bool check(){
19     int l=strlen(s);
20     if (l%L!=0) return false;
21     for(int i=0;i<l;i++){
22         if (s[i]!=ss[i%L]) return false;
23     }
24     return true;
25 }
26 int T;
27 int main(){
28     int n1,n2;
29     scanf("%d\n",&T);
30     for(int i=0;i<T;i++){
31         bool ans;
32         gets(s);
33         n1=n2=0;
34         if (strlen(s)==0){
35             printf("Yes\n");
36             continue;
37         }
38         for(int i=0;i<strlen(s);i++){
39             if (s[i]=='!') n1++;
40             if (s[i]=='_') n2++;
41         }
42         if (n2==0){
43             if (n1==0) ans=false;
44             if (check()) ans=true;else ans=false;
45         }
46         if (n2==1){
47             if (n1==0) ans=true;
48             if (n1>0) ans=false;
49         }
50         if (n2>=2){
51             ans=false;
52         }
53         if (ans) printf("Yes\n");else printf("No\n");
54     }
55     return 0;
56 }
View Code

 

posted @ 2014-04-06 20:46  little_w  阅读(144)  评论(0编辑  收藏  举报