https://icpc.baylor.edu/regionals/finder/north-america-qualifier-2015
一个人打。。。。
B
概率问题公式见代码
1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #include <queue> 5 #include <stack> 6 #include <vector> 7 #include <algorithm> 8 using namespace std; 9 #define clc(a,b) memset(a,b,sizeof(a)) 10 #define inf 0x3f3f3f3f 11 const int N=10010; 12 const int MOD = 1e9+7; 13 #define LL long long 14 void fre() { 15 freopen("in.txt","r",stdin); 16 } 17 18 inline int r(){ 19 int x=0,f=1;char ch=getchar(); 20 while(ch>‘9‘||ch<‘0‘){if(ch==‘-‘) f=-1;ch=getchar();} 21 while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} 22 return x*f; 23 } 24 25 int countt; 26 int comb1(int m,int k) 27 { 28 int i; 29 for (i=m;i>=k;i--) 30 { 31 if (k>1) 32 { 33 comb1(i-1,k-1); 34 } 35 else 36 { 37 countt++; 38 } 39 } 40 return countt; 41 } 42 43 int main(){ 44 // fre(); 45 int T; 46 int R,s,x,y,w; 47 T=r(); 48 while(T--){ 49 double p1=0.0; 50 int num; 51 cin>>R>>s>>x>>y>>w; 52 double p=(s-R+1)*1.0/s; 53 double ans=0.0; 54 for(int i=x;i<=y;i++){ 55 int c=y-i; 56 p1=1.0; 57 double p2=1.0-p; 58 while(c--){ 59 p1*=p2; 60 } 61 int cc=i; 62 double P=1.0; 63 for(int j=1;j<=i;j++){ 64 P*=p; 65 } 66 // cout<<i<<" "<<P<<endl; 67 countt=0; 68 num=comb1(y,i); 69 // cout<<P<<" "<<p1<<" "<<num<<endl; 70 ans+=P*p1*num; 71 } 72 // cout<<ans<<endl; 73 if(ans*w>1) 74 printf("yes\n"); 75 else 76 printf("no\n"); 77 } 78 return 0; 79 }
F
水题
输出字符串中缺少的字母
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<queue> 5 #include<stack> 6 #include<algorithm> 7 using namespace std; 8 #define clc(a,b) memset(a,b,sizeof(a)) 9 #define inf 0x3f3f3f3f 10 const int N=10010; 11 const int MOD = 1e9+7; 12 #define LL long long 13 void fre(){freopen("in.txt","r",stdin); } 14 // inline int r(){ 15 // int x=0,f=1;char ch=getchar(); 16 // while(ch>‘9‘||ch<‘0‘){if(ch==‘-‘) f=-1;ch=getchar();} 17 // while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} 18 // return x*f; 19 // } 20 int a[30]; 21 char ans[30]; 22 int main() 23 { 24 25 int T; 26 scanf("%d",&T); 27 getchar(); 28 while(T--) 29 { 30 clc(a,0); 31 clc(ans,0); 32 string s; 33 getline(cin,s); 34 for(int i = 0; i < s.length(); i ++){ 35 if(s[i] >= ‘a‘ && s[i] <= ‘z‘) 36 a[s[i] - ‘a‘] ++; 37 if(s[i] >= ‘A‘ && s[i] <= ‘Z‘) 38 a[s[i] - ‘A‘] ++; 39 } 40 int k = 0; 41 for(int i = 0; i < 26; i ++){ 42 if(!a[i]){ 43 ans[k++] = i + ‘a‘; 44 } 45 } 46 if(k ==0) { 47 printf("pangram\n"); 48 } 49 else{ 50 printf("missing "); 51 for(int i = 0; i< k; i ++){ 52 printf("%c",ans[i]); 53 } 54 printf("\n"); 55 } 56 } 57 return 0; 58 }
G
多个人过河每次船上必须有一人问最短时间
1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #include <queue> 5 #include <stack> 6 #include <vector> 7 #include <algorithm> 8 using namespace std; 9 #define clc(a,b) memset(a,b,sizeof(a)) 10 #define inf 0x3f3f3f3f 11 const int N=10010; 12 const int MOD = 1e9+7; 13 #define LL long long 14 void fre() { 15 freopen("in.txt","r",stdin); 16 } 17 18 inline int r(){ 19 int x=0,f=1;char ch=getchar(); 20 while(ch>‘9‘||ch<‘0‘){if(ch==‘-‘) f=-1;ch=getchar();} 21 while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} 22 return x*f; 23 } 24 25 int TravelBridge(std::vector<int> times) 26 { 27 size_t length = times.size(); 28 if(length <= 2) 29 return times[length-1]; 30 else if(length == 3) 31 { 32 return times[0] + times[1] + times[2]; 33 } 34 else 35 { 36 int totaltime = 0; 37 int a = times[0]; 38 int b = times[1]; 39 int z = times[length-1]; 40 int y = times[length-2]; 41 if(b*2 < a + y) 42 { 43 times.erase(times.end()-1); 44 times.erase(times.end()-1); 45 totaltime += b + a + z + b + TravelBridge(times); 46 } 47 else 48 { 49 times.erase(times.end()-1); 50 totaltime += z + a + TravelBridge(times); 51 } 52 return totaltime; 53 } 54 } 55 56 int main(){ 57 int n; 58 n=r(); 59 vector<int> v; 60 for(int i=0;i<n;i++){ 61 int x; 62 x=r(); 63 v.push_back(x); 64 } 65 sort(v.begin(),v.end()); 66 int ans=TravelBridge(v); 67 printf("%d\n",ans); 68 return 0; 69 }
H
水题
旋转矩阵再输出
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<queue> 5 #include<stack> 6 #include<algorithm> 7 using namespace std; 8 #define clc(a,b) memset(a,b,sizeof(a)) 9 #define inf 0x3f3f3f3f 10 const int N=10010; 11 const int MOD = 1e9+7; 12 #define LL long long 13 void fre() { 14 freopen("in.txt","r",stdin); 15 } 16 17 inline int r(){ 18 int x=0,f=1;char ch=getchar(); 19 while(ch>‘9‘||ch<‘0‘){if(ch==‘-‘) f=-1;ch=getchar();} 20 while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} 21 return x*f; 22 } 23 24 char s[10010]; 25 char a[110][110]; 26 int main() { 27 // fre(); 28 int T; 29 T=r(); 30 // getchar(); 31 while(T--) { 32 scanf("%s",s); 33 int len = strlen(s); 34 int q = 0; 35 for(; ; q ++) { 36 if(q * q >= len) { 37 break; 38 } 39 } 40 // cout<<s[0]<<endl; 41 int pos; 42 for(int i = 0; i < q; i ++) { 43 for(int j = 0; j < q ; j ++) { 44 pos = i * q + j; 45 if(pos >= len) { 46 a[i][j] = ‘*‘; 47 } else { 48 a[i][j] = s[pos]; 49 } 50 } 51 } 52 // printf("%c\n",a[0][0]); 53 // for(int i=0;i<q;i++){ 54 // for(int j=0;j<q;j++){ 55 // printf("%c ",a[i][j]); 56 // } 57 // printf("\n"); 58 // } 59 for(int j = 0; j < q ; j ++) { 60 for(int i = q - 1; i >= 0; i --) { 61 if(a[i][j] != ‘*‘) 62 printf("%c",a[i][j]); 63 } 64 } 65 printf("\n"); 66 } 67 return 0; 68 }
J
把单词映射成数字
从起点到终点搜索
1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <list> 5 #include <map> 6 #include <stack> 7 #include <vector> 8 #include <cstring> 9 #include <sstream> 10 #include <string> 11 #include <cmath> 12 #include <queue> 13 using namespace std; 14 #define clc(a,b) memset(a,b,sizeof(a)) 15 #define inf 0x3f3f3f3f 16 const int N=10010; 17 const int MOD = 1e9+7; 18 #define LL long long 19 void fre() { 20 freopen("in.txt","r",stdin); 21 } 22 inline int r() { 23 int x=0,f=1; 24 char ch=getchar(); 25 while(ch>‘9‘||ch<‘0‘) { 26 if(ch==‘-‘) f=-1; 27 ch=getchar(); 28 } 29 while(ch>=‘0‘&&ch<=‘9‘) { 30 x=x*10+ch-‘0‘; 31 ch=getchar(); 32 } 33 return x*f; 34 } 35 36 int a[35][35] = {0}; 37 int p[35]; 38 string s[35]; 39 int n; 40 int ans[100]; 41 bool idx[35] = {false}; 42 int num = 1; 43 map<string,int> mapp; 44 45 void dfs(int u,int v) { 46 if(u == v) 47 return; 48 idx[u] = true; 49 for(int i = 1; i <= num; i ++) { 50 if(a[u][i] == 1 && idx[i] == false) { 51 p[i] =u; 52 dfs(i,v); 53 } 54 } 55 idx[u] = false; 56 } 57 58 int main() { 59 clc(a,0); 60 mapp.clear(); 61 n=r(); 62 // getchar(); 63 string line,x; 64 string s1,s2; 65 int k = 0; 66 int t; 67 bool flag = false; 68 int u,v; 69 for(int i =0; i < n; i ++) { 70 getline(cin,line); 71 stringstream ss(line); 72 ss>>x; 73 if(mapp[x] == 0) { 74 mapp[x] = num; 75 s[num] = x; 76 num ++; 77 } 78 u = mapp[x]; 79 while(ss >> x) { 80 if(mapp[x] == 0) { 81 mapp[x] = num; 82 s[num] = x; 83 num ++; 84 } 85 v = mapp[x]; 86 a[u][v] = 1; 87 a[v][u] = 1; 88 } 89 } 90 cin>>s1>>s2; 91 if(mapp[s1] == 0) { 92 mapp[s1] = num; 93 num ++; 94 } 95 u= mapp[s1]; 96 if(mapp[s2] == 0) { 97 mapp[s2] = num; 98 num ++; 99 } 100 v = mapp[s2]; 101 dfs(u,v); 102 p[u] = -1; 103 t = v; 104 while(t != -1) { 105 ans[k ++] = t; 106 if(t == 0) { 107 flag = true; 108 break; 109 } 110 t = p[t]; 111 } 112 if(flag == true) { 113 printf("no route found\n"); 114 return 0; 115 } 116 for(int i = k - 1; i >= 1; i --) { 117 cout<<s[ans[i]]<<" "; 118 } 119 cout<<s[v]<<endl; 120 121 }
一个人打也挺好玩的
时间: 2024-10-18 01:22:57