题目地址:

http://acdream.info/onecontest/1052#overview

A:

简单的字符串问题

 1 // File Name: a.cpp
 2 // Author: darkdream
 3 // Created Time: 2014年07月11日 星期五 19时06分11秒
 4  
 5 #include<vector>
 6 #include<list>
 7 #include<map>
 8 #include<set>
 9 #include<deque>
10 #include<stack>
11 #include<bitset>
12 #include<algorithm>
13 #include<functional>
14 #include<numeric>
15 #include<utility>
16 #include<sstream>
17 #include<iostream>
18 #include<iomanip>
19 #include<cstdio>
20 #include<cmath>
21 #include<cstdlib>
22 #include<cstring>
23 #include<ctime>
24 #include<climits>
25 #include<queue>
26  
27 using namespace std;
28 char str[200];
29 int main(){
30    int t ;
31    scanf("%d",&t);
32    char str1[120];
33    while(t--)
34    {
35       memset(str,0,sizeof(str));
36       memset(str1,0,sizeof(str1));
37       scanf("%s",str);
38       for(int i = 0 ;; i ++ )
39       {
40          str1[i] = 'A';
41          if(!strstr(str,str1))
42             {
43               puts(str1);
44               break;
45             }
46       }
47    }
48     
49    return 0;
50 }
A

B:

搜索DP博弈

  1 // File Name: b.cpp
  2 // Author: darkdream
  3 // Created Time: 2014年07月12日 星期六 10时44分56秒
  4  
  5 #include<vector>
  6 #include<list>
  7 #include<map>
  8 #include<set>
  9 #include<deque>
 10 #include<stack>
 11 #include<bitset>
 12 #include<algorithm>
 13 #include<functional>
 14 #include<numeric>
 15 #include<utility>
 16 #include<sstream>
 17 #include<iostream>
 18 #include<iomanip>
 19 #include<cstdio>
 20 #include<cmath>
 21 #include<cstdlib>
 22 #include<cstring>
 23 #include<ctime>
 24 #include<climits>
 25 #include<queue>
 26  
 27 using namespace std;
 28 long long n , m , a;
 29 int log10(long long n ,long long a)
 30 {
 31     double t = (log(a)/log(n));
 32     return   (t+1.0 - 1e-8);
 33  
 34 }
 35 long long P(long long x)
 36 {
 37   long long ans = 1;
 38   for(int i =1 ;i <= x ;i ++)
 39       ans *= 2 ;
 40   return ans ;
 41 }
 42 int dfs(long long  n,long long  m )
 43 {
 44     if(n != 1)
 45     {
 46         double t = (log(a)/log(n));
 47         long long  k = (t+1.0 - 1e-8);
 48         if(k <= m )
 49         {
 50             return 1;
 51         }
 52     }
 53     int t1;
 54     int t2;
 55     if(m == 1 && n*n >= a )
 56     {
 57         t1 = 1;
 58         t2 = (a - n )%2;
 59     }
 60     else if(n == 1 &&  P(m) >= a)
 61     {
 62         t1 = 1;
 63         t2 = dfs(n+1,m);
 64     }else{
 65         t1 = dfs(n+1,m);
 66         t2 = dfs(n,m+1);
 67     }
 68     if(t1 && t2)
 69         return 0 ;
 70     if(!t1 && !t2)
 71         return 1;
 72     return 1;
 73 }
 74 int main(){
 75 //     freopen("cin.txt","r",stdin);
 76 //    freopen("cout1.txt","w",stdout);
 77  
 78     while(scanf("%lld %lld %lld",&n,&m,&a) != EOF)
 79     {
 80         if(n == 1)
 81         {
 82             if(log10(n+1,a) <= m)
 83             {     printf("draw\n");
 84                continue;
 85             }
 86             int t1 = dfs(n,m);
 87         }
 88         if(n!= 1)
 89             if(log10(n,a) <= m)
 90             {
 91                 printf("lose\n");
 92                 continue;
 93             }
 94         int t = dfs(n,m);
 95         if(t == 1 )
 96             printf("win\n");
 97         else printf("lose\n");
 98     }
 99     return 0;
100 }
View Code

C:

状态压缩+dp

这个题目状态压缩需要考虑一些情况,

一共有三种情况,  被保护,没有被保护,还有落子点.

然后就是对所有情况进行讨论即可.

  1 // File Name: c.cpp
  2 // Author: darkdream
  3 // Created Time: 2014年07月13日 星期日 16时44分27秒
  4 
  5 #include<vector>
  6 #include<list>
  7 #include<map>
  8 #include<set>
  9 #include<deque>
 10 #include<stack>
 11 #include<bitset>
 12 #include<algorithm>
 13 #include<functional>
 14 #include<numeric>
 15 #include<utility>
 16 #include<sstream>
 17 #include<iostream>
 18 #include<iomanip>
 19 #include<cstdio>
 20 #include<cmath>
 21 #include<cstdlib>
 22 #include<cstring>
 23 #include<ctime>
 24 #include<climits>
 25 #include<queue>
 26 
 27 using namespace std;
 28 #define di  3
 29 int dp[11][60000];
 30 int hs[2000000];
 31 int n,m,row;
 32 int num[10],pp[10];
 33 int visit[10][10];
 34 void change1(int zt)
 35 {
 36     int now = zt;
 37     int  k = 0 ; 
 38     int num[20];
 39     memset(num,0,sizeof(num));
 40     while(now)
 41     {
 42         num[++k] = now % di;
 43         now/= di;
 44     }
 45     for(int i =1 ;i<= 10;i ++)
 46         printf("%d ",num[i]);
 47     printf("\n");
 48 }
 49 
 50 void dfs(int  pos ,int  status,int a)
 51 {
 52     if(pos > n )
 53     {
 54     //    printf("%d %d\n",status,a);
 55     //    change1(status);
 56         if(dp[row][status] == -1)
 57             dp[row][status] = a;
 58         else{
 59     //        printf("update %d %d\n",dp[row][status],a);
 60             dp[row][status] = min(dp[row][status],a);
 61         }
 62         return ;
 63     }
 64     if(pos == 1){
 65         if(num[pos] == 1)
 66         {
 67             dfs(pos+1,status+2*pp[pos],a);
 68         }else if(num[pos] == 2){
 69             if(visit[row][pos] == 0)
 70                 dfs(pos+1,status+pp[pos],a+1);
 71             dfs(pos+1,status,a);
 72         }else {
 73             if(visit[row][pos] == 1)
 74                 return;
 75             else dfs(pos+1,status+pp[pos],a+1);
 76         }
 77         return ;
 78     }
 79     int t = status/pp[pos-1];
 80     if(t == 1){  
 81         if(num[pos] == 0 )
 82             return;
 83         else  
 84             dfs(pos+1,status + 2*pp[pos],a);
 85     }else if(t == 2){
 86         if(num[pos] == 1){  //左边为2  上边为1
 87             dfs(pos+1,status+2*pp[pos],a);
 88         }else if(num[pos] == 2){  //左边为2 上边为2 ,
 89             if(visit[row][pos] == 0)
 90             {
 91                 dfs(pos+1,status+pp[pos],a+1);
 92             }
 93             dfs(pos+1,status,a);
 94         }else {
 95             if(visit[row][pos] == 0)
 96             {
 97                 dfs(pos+1,status+pp[pos],a+1);
 98             }else{
 99                 return ;
100             }
101         }
102     }else {
103         if(num[pos] == 1){  //左边为0  上边为1
104             dfs(pos+1,status+ 2*pp[pos],a);
105         }else if(num[pos] == 2){  //左边为0 上边为2 ,
106             if(visit[row][pos] == 0)
107             {
108                 dfs(pos+1,status+pp[pos]+2*pp[pos-1],a+1);
109             }
110             dfs(pos+1,status,a);
111         }else {//左边为0  上边为0
112             if(visit[row][pos] == 0)
113             {
114                 dfs(pos+1,status+pp[pos]+2*pp[pos-1],a+1);
115             }else{
116                 return ;
117             }
118         }
119     }
120 
121 }
122 void change(int zt)
123 {
124     int now = zt;
125     int  k = 0 ; 
126     memset(num,0,sizeof(num));
127     if(now == 0 )
128         return ; 
129     while(now){
130         num[++k] = now % di;
131         now/= di;
132     }
133 }
134 int ok(int zt)
135 {
136     //printf("%d**\n",zt);
137     for(int k = n; k >= 1 ; k -- )
138      {
139          if(zt/pp[k] == 0 )
140              return  0 ; 
141          zt = zt % pp[k]; 
142      }
143     return 1;
144 }
145 int main(){
146     pp[0] = 1;
147     pp[1] = 1; 
148     for(int i = 2;i <= 10 ;i ++) pp[i] = pp[i-1]*di;
149     while(scanf("%d %d",&n,&m) != EOF)
150     {
151 
152         memset(visit,0,sizeof(visit));
153         memset(num,0,sizeof(num));
154         for(int i =1;i <= m; i ++)
155         {
156             int a,b; 
157             scanf("%d %d",&a,&b);
158             visit[a][b] = 1; 
159         }
160         memset(dp,-1,sizeof(dp));
161         int temp = 0 ;
162         for(int i =1; i <= n;i ++)
163             temp += 2* pp[i];
164         dp[0][temp] = 0 ;
165 
166         for(row = 1 ;row <= n;row ++)
167         {
168             for(int i = 0;i <= pp[n+1]; i ++)
169             {
170                 if(dp[row-1][i] != -1)
171                 {
172                     change(i);
173                     dfs(1,0,dp[row-1][i]);
174                 }
175             }
176     //        printf("*****\n");
177         }
178         int ans = 1000 ;
179         for(int i = 0 ;i <= pp[n+1]; i ++)
180         {
181            if(dp[n][i] != -1)
182            {
183              if(dp[n][i] < ans && ok(i))
184              {
185                   ans = min(dp[n][i],ans);
186              }
187            }
188         }
189         if(ans == 1000)
190             printf("-1\n");
191         else 
192             printf("%d\n",ans);
193     } 
194     return 0;
195 }
View Code

 

 

F:

kruskal + 贪心

 1 // File Name: f.cpp
 2 // Author: darkdream
 3 // Created Time: 2014年07月11日 星期五 20时47分15秒
 4  
 5 #include<vector>
 6 #include<list>
 7 #include<map>
 8 #include<set>
 9 #include<deque>
10 #include<stack>
11 #include<bitset>
12 #include<algorithm>
13 #include<functional>
14 #include<numeric>
15 #include<utility>
16 #include<sstream>
17 #include<iostream>
18 #include<iomanip>
19 #include<cstdio>
20 #include<cmath>
21 #include<cstdlib>
22 #include<cstring>
23 #include<ctime>
24 #include<climits>
25 #include<queue>
26  
27 using namespace std;
28 int n , m ;
29 struct node{
30     int a,b,l,c;
31 }a[100005];
32 int f[10005];
33 int hs[10005];
34 int cmp(struct node a ,struct node b)
35 {
36     if(a.l == b.l)
37     {
38         return a.c < b.c ;
39     }
40     return a.l < b.l;
41 }
42 int find(int x)
43 {
44    return   x == f[x]?x:f[x] = find(f[x]);
45 }
46 int main(){
47  
48     while(scanf("%d %d",&n,&m) != EOF){
49         memset(a,0,sizeof(a));
50         memset(f,0,sizeof(f));
51         for(int i = 1;i <= n; i ++)
52             f[i] = i ;
53         for(int i =1 ;i <= m;i ++)
54         {
55             scanf("%d %d %d %d",&a[i].a,&a[i].b,&a[i].l,&a[i].c);                            
56         }
57         sort(a+1,a+1+m,cmp);
58         int sumc,suml;
59         sumc = suml = 0 ;
60         for(int i = 1;i <= m;i ++)
61         {
62             int ta = find(a[i].a);
63             int tb = find(a[i].b);
64             if(ta != tb)
65             {
66                 f[tb] = ta;
67                 sumc += a[i].c ;
68                 suml += a[i].l ;
69             }
70         }
71         int ok = 0 ;
72         memset(hs,0,sizeof(hs));
73         for(int i =1;i <= n;i ++)
74         {
75             hs[find(i)] ++ ;
76             if(hs[find(i)] == n)
77                 ok = 1;
78         }
79         if(ok)
80             printf("%d %d\n",suml,sumc);
81         else printf("-1 -1\n");
82     }
83     return 0 ;
84 }
View Code

 

 

J:

快捷计算:

 1 // File Name: b.cpp
 2 // Author: darkdream
 3 // Created Time: 2014年07月11日 星期五 19时53分57秒
 4  
 5 #include<vector>
 6 #include<list>
 7 #include<map>
 8 #include<set>
 9 #include<deque>
10 #include<stack>
11 #include<bitset>
12 #include<algorithm>
13 #include<functional>
14 #include<numeric>
15 #include<utility>
16 #include<sstream>
17 #include<iostream>
18 #include<iomanip>
19 #include<cstdio>
20 #include<cmath>
21 #include<cstdlib>
22 #include<cstring>
23 #include<ctime>
24 #include<climits>
25 #include<queue>
26  
27 using namespace std;
28 #define mod 1000000007
29 long long  num[1200];
30 long long temp[20][1200];
31 int main(){
32   int  n;
33   scanf("%d",&n);
34   num[1] = 1;
35   for(int i = 2;i <= n;i ++)
36   {
37       num[i] = num[i-1] * 10 % mod;
38   }
39   for(int i = 0 ;i <= 9 ;i ++)
40     temp[i][1] = i;
41   for(int i = 1;i <= 9;i ++)
42   {
43      for(int j = 2;j <= n;j ++)
44      {
45         temp[i][j] = (temp[i][j-1] + i * num[j])%mod;
46      }
47   }
48    
49   long long  ans = 0 ;
50   for(int i =0 ;i < n;i ++ )
51   {
52     for(int j = 0 ;j < n;j ++)
53     {
54        int t;
55        scanf("%1d",&t);
56        ans = (ans + temp[t][n-j]*(j+1) + temp[t][n-i]*(i+1)) % mod;
57     }
58   }
59   printf("%lld\n",ans);
60 return 0;
61 }
View Code

 

posted on 2014-07-12 18:55  dark_dream  阅读(171)  评论(0编辑  收藏  举报