标签:
Problem A Codeforces 451A
1 #include <cstdio> 2 int main(){ 3 int a,b; 4 scanf("%d%d",&a,&b); 5 a = a < b ? a : b; 6 printf(a&1 ? "Akshat" : "Malvika"); 7 return 0; 8 }
Problem B Codeforces 451B
1 #include <cstdio> 2 #include <algorithm> 3 using namespace std; 4 const int maxn = 100010; 5 struct Node{ 6 int val,id; 7 bool operator < (const Node& rhs) const{ 8 return val < rhs.val; 9 } 10 }node[maxn]; 11 12 int main(){ 13 int n,l = -1,r; 14 bool flag = 1; 15 scanf("%d",&n); 16 for(int i = 1;i <= n;i++){ 17 scanf("%d",&node[i].val); 18 node[i].id = i; 19 } 20 sort(node+1,node+n+1); 21 node[n+1].id = -1; 22 for(int i = 1;i <= n;i++){ 23 if(node[i].id != i){ 24 l = i; 25 break; 26 } 27 } 28 if(l == -1){ 29 printf("yes\n1 1\n"); 30 return 0; 31 } 32 for(int i = l;i <= n;i++){ 33 if(node[i].id - node[i+1].id != 1){ 34 r = i; 35 break; 36 } 37 } 38 for(int i = r+1;i <= n;i++){ 39 if(node[i].id != i){ 40 flag = false; 41 break; 42 } 43 } 44 if(flag) printf("yes\n%d %d\n",l,r); 45 else printf("no\n"); 46 return 0; 47 }
Problem C FZU 1907
1 #include <cstdio> 2 #include <cstring> 3 const int maxn = 1000010; 4 int p[maxn],ans[maxn]; 5 char str[maxn]; 6 7 void get_p(int len){ 8 p[1] = 0; 9 int j = 0; 10 for(int i = 2;i <= len;i++){ 11 while(j > 0 && str[j+1] != str[i]) j = p[j]; 12 if(str[j+1] == str[i]) j++; 13 p[i] = j; 14 } 15 } 16 17 int main(){ 18 int nkase; 19 scanf("%d",&nkase); 20 for(int kase = 1;kase <= nkase;kase++){ 21 scanf("%s",str+1); 22 int len = strlen(str+1); 23 get_p(len); 24 int t = p[len],cnt = 0; 25 while(t){ 26 ans[cnt++] = len-t; 27 t = p[t]; 28 } 29 ans[cnt++] = len; 30 printf("Case #%d: %d\n",kase,cnt); 31 for(int i = 0;i < cnt-1;i++) printf("%d ",ans[i]); 32 printf("%d\n",ans[cnt-1]); 33 } 34 return 0; 35 }
Problem D UVA 10608
1 #include <cstdio> 2 #include <algorithm> 3 using namespace std; 4 const int maxn = 30010; 5 int fa[maxn],num[maxn],ans; 6 7 int find(int u){ 8 return fa[u] == u ? u : fa[u] = find(fa[u]); 9 } 10 11 void Union(int u,int v){ 12 int a = find(u); 13 int b = find(v); 14 if(a != b){ 15 fa[a] = b; 16 num[a] += num[b]; 17 num[b] = num[a]; 18 ans = max(ans,num[b]); 19 } 20 } 21 22 int main(){ 23 int kase,n,m,a,b; 24 scanf("%d",&kase); 25 while(kase--){ 26 scanf("%d%d",&n,&m); 27 for(int i = 1;i <= n;i++){ 28 fa[i] = i; 29 num[i] = 1; 30 } 31 ans = 0; 32 for(int i = 0;i < m;i++){ 33 scanf("%d%d",&a,&b); 34 Union(a,b); 35 } 36 printf("%d\n",ans); 37 } 38 return 0; 39 }
Problem E Codeforces 237C
1 #include <cstdio> 2 #include <cstring> 3 const int maxn = 1000010; 4 int sum[maxn],a,b,k; 5 bool pri[maxn]; 6 void init(){ 7 for(int i = 2;i < maxn;i++){ 8 sum[i] = sum[i-1]; 9 if(pri[i]) continue; 10 sum[i]++; 11 for(int j = i+i;j < maxn;j += i) 12 pri[j] = 1; 13 } 14 } 15 16 bool check(int mid){ 17 for(int i = a;i <= b-mid+1;i++){ 18 if(sum[i+mid-1]-sum[i-1] < k) return 0; 19 } 20 return 1; 21 } 22 23 int main(){ 24 init(); 25 scanf("%d%d%d",&a,&b,&k); 26 if(sum[b]-sum[a-1] < k){ 27 printf("-1\n"); 28 return 0; 29 } 30 int l = 1,r = b-a+1,ans; 31 while(l <= r){ 32 int mid = (l+r)>>1; 33 if(check(mid)) ans = mid,r = mid-1; 34 else l = mid+1; 35 } 36 printf("%d\n",ans); 37 }
Problem F Codeforces 16E
1 #include <cstdio> 2 #include <cstring> 3 double dp[1<<18]; 4 double mat[18][18]; 5 6 int bitcount(int t){ 7 int ret = 0; 8 while(t){ 9 ret += t&1; 10 t >>= 1; 11 } 12 return ret; 13 } 14 15 int main(){ 16 int n; 17 scanf("%d",&n); 18 for(int i = 0;i < n;i++){ 19 for(int j = 0;j < n;j++){ 20 scanf("%lf",&mat[i][j]); 21 } 22 } 23 dp[(1<<n)-1] = 1; 24 for(int i = (1<<n)-1;i >= 1;i--){ 25 int bit = bitcount(i); 26 if(bit == 1) continue; 27 double p = 2*dp[i]/bit/(bit-1); 28 for(int j = 0;j < n;j++)if(i&(1<<j)){ 29 for(int k = 0;k < n;k++)if(i&(1<<k)){ 30 dp[i^(1<<k)] += p*mat[j][k]; 31 } 32 } 33 } 34 for(int i = 0;i < n;i++){ 35 printf("%.6f ",dp[1<<i]); 36 } 37 return 0; 38 }
标签:
原文地址:http://www.cnblogs.com/zhexipinnong/p/3870451.html