North America Qualifier (2015)

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

North America Qualifier (2015)的相关文章

ACM-ICPC North America Qualifier 2014 Eight Queens

题意:问图是否满足八皇后. 解题思路:hash,dp,位运算 解题代码: 我的搓代码. 1 // File Name: a.cpp 2 // Author: darkdream 3 // Created Time: 2015年03月14日 星期六 12时00分44秒 4 5 #include<vector> 6 #include<list> 7 #include<map> 8 #include<set> 9 #include<deque> 10

ACM-ICPC North America Qualifier 2014 Units

题意:题如其名,给你n个单位 ,以及n-1个单位换算信息,让你把完整的单位换算链写出来. 解题思路:搜索 或者 floyd 解题代码: 1 // File Name: j.cpp 2 // Author: darkdream 3 // Created Time: 2015年03月14日 星期六 15时56分31秒 4 5 #include<vector> 6 #include<list> 7 #include<map> 8 #include<set> 9 #

ACM-ICPC North America Qualifier 2014 Narrow Art Gallery

题意:一个宽为2长为n的画廊,每个格子有一个值,问你关闭k个格子,使得画廊不堵塞且剩余值最大. 解题思路:dp[i][j][0/1]  表示 第 i个位置 ,选取第 j个格子关闭 ,关闭i位置的k格子的最小值. 解题代码: 1 // File Name: h.cpp 2 // Author: darkdream 3 // Created Time: 2015年03月14日 星期六 12时28分16秒 4 5 #include<vector> 6 #include<list> 7 #

ACM-ICPC North America Qualifier 2014 Human Cannonball Run

题意:在一个二维平面中 一个人走路的速度是 5m/s , 平面中有n个大炮,射程固定为50m且时间为2秒  ,问你最短时间. 解题思路:最短路 解题代码: 1 // File Name: e.cpp 2 // Author: darkdream 3 // Created Time: 2015年03月14日 星期六 16时47分54秒 4 5 #include<vector> 6 #include<list> 7 #include<map> 8 #include<s

ACM-ICPC North America Qualifier 2014 Tractor

题意:一个奶牛从(0,0)点开始跳,它只能朝着x轴正向和y轴正向跳,且第i次跳只能跳 2^(i-1)个距离,问你  矩阵((0,0),(A,B))中奶牛能跳到多少个点. 解题思路:你最后发现 每次跳一步的点都在一条斜线上. 解题代码: 1 // File Name: t.cpp 2 // Author: darkdream 3 // Created Time: 2015年03月14日 星期六 13时37分30秒 4 5 #include<vector> 6 #include<list&g

East Central North America Region 2015

E 每过一秒,当前点会把它的值传递给所有相邻点,问t时刻该图的值 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 <

2015 UESTC Winter Training #6【Regionals 2010 &gt;&gt; North America - Rocky Mountain】

2015 UESTC Winter Training #6 Regionals 2010 >> North America - Rocky Mountain A - Parenthesis 给一个长度不多于1000的表达式,只包含小写字母,加法运算,省略乘号的乘法运算和括号,输出去掉多余括号的表达式 括号匹配可以使用栈操作,只有两种情况可以去掉这一对括号: 左括号的左边是左边界.加法符号.左括号,并且右括号右边是有右边界.加法符号.右括号 如果括号内没有加法运算(括号内的括号里,也就是下一级括

MPI Maelstrom(East Central North America 1996)(poj1502)

MPI Maelstrom 总时间限制:  1000ms 内存限制:  65536kB 描述 BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierarchical communication subsystem. Valentine McKee's research advisor

That Diesel powered running watches north america doesn&#39;t need shift and legal requirements within any specific time

The form belonging to the Diesel's court case is totally distinct in addition to being very unlikely to find that remarkable high-quality because of shots solely. That face belonging to the Diesel powered is without a doubt everything that might be l