Codeforces Education Round 11

A(模拟+数学)

题意:在一个数列当中最少添加多少个数可以使它们两两互质,并打印出添加以后的数列

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <string>
 5 #include <vector>
 6 #include <algorithm>
 7 #include <set>
 8 #include <map>
 9 #include <bitset>
10 #include <cmath>
11 #include <queue>
12 #include <stack>
13 using namespace std;
14 const int maxn=2020;
15 const int maxm=1000000000;
16 int a[maxn];
17 int gcd(int a,int b)
18 {
19     if(b==0) return a;
20     return gcd(b,a%b);
21 }
22 int n;
23 int main()
24 {
25     while(cin>>n)
26     {
27         for(int i=0;i<n;i++)
28             scanf("%d",&a[i]);
29         vector<int>b;
30         int cnt=0;
31         for(int i=0;i<n-1;i++)
32         {
33             if(gcd(a[i],a[i+1])>=2){
34                 cnt++;
35                 int k;
36                 for(int j=1;j<=maxm;j++){
37                     if(gcd(a[i],j)<2&&gcd(j,a[i+1])<2){
38                         k=j; break;
39                     }
40                 }
41                 b.push_back(a[i]);
42                 b.push_back(k);
43             }
44             else{
45                 b.push_back(a[i]);
46             }
47         }
48         b.push_back(a[n-1]);
49         cout<<cnt<<endl;
50         for(int i=0;i<b.size()-1;i++)
51             cout<<b[i]<<" ";
52         cout<<b[b.size()-1]<<endl;
53     }
54     return 0;
55 }

B(队列模拟)

题意:根据公交车上下车的顺序,打印下车的顺序

分析:用队列直接进行模拟即可

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <string>
 5 #include <vector>
 6 #include <algorithm>
 7 #include <set>
 8 #include <map>
 9 #include <bitset>
10 #include <cmath>
11 #include <queue>
12 #include <stack>
13 using namespace std;
14 const int maxn=150;
15 int a[maxn][4];
16 int n,m;
17 int main()
18 {
19     while(cin>>n>>m)
20     {
21         queue<int>que[4];
22         int k=1;
23         int cnt=0;
24         for(;;)
25         {
26             if(cnt>=n) break;
27             if(k>m) break;
28             que[0].push(k);
29             k++;
30             if(k>m) break;
31             que[3].push(k);
32             k++;
33             cnt++;
34         }
35         for(;;)
36         {
37             if(k>m) break;
38             que[1].push(k);
39             k++;
40             if(k>m)  break;
41             que[2].push(k);
42             k++;
43         }
44         vector<int>b;
45         int t;
46         int f1=0,f2=0,f3=0,f4=0;
47         for(;;)
48         {
49             if(que[1].empty()){
50                 f2=1;
51             }else{
52                 t=que[1].front();
53                 que[1].pop();
54                 b.push_back(t);
55             }
56             if(que[0].empty()){
57                 f1=1;
58             }else{
59                 t=que[0].front();
60                 que[0].pop();
61                 b.push_back(t);
62             }
63              if(que[2].empty()){
64                 f3=1;
65             }else{
66                 t=que[2].front();
67                 que[2].pop();
68                 b.push_back(t);
69             }
70              if(que[3].empty()){
71                 f4=1;
72             }else{
73                 t=que[3].front();
74                 que[3].pop();
75                 b.push_back(t);
76             }
77              if(f1&&f2&&f3&&f4) break;
78         }
79         for(int i=0;i<b.size()-1;i++)
80             cout<<b[i]<<" ";
81         cout<<b[b.size()-1]<<endl;
82     }
83     return 0;
84 }

时间: 2024-10-10 13:17:16

Codeforces Education Round 11的相关文章

状压dp找寻环的个数 Codeforces Beta Round #11 D

http://codeforces.com/problemset/problem/11/D 题目大意:给你n个点,m条边,找该图中有几个换 思路:定义dp[i][j]表示i是圈的集合,j表示该集合的终点,定义起点为这些走过的点里面最小的 //看看会不会爆int!数组会不会少了一维! //取物问题一定要小心先手胜利的条件 #include <bits/stdc++.h> using namespace std; #define LL long long #define ALL(a) a.begi

Codeforces Beta Round #91 (Div. 1 Only) E. Lucky Array

E. Lucky Array Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467are not. Petya has an arra

CodeForces Beta Round #1

Codeforces Beta Round #1 A. Theatre Square [题意]一个n*m的矩形广场,用a*a的方形石板铺设,问最少需要多少块石板能铺满广场. [思路]水题,从n方向来看能能够铺设ceil(n/a)块,从m方向来看能能够铺设ceil(m/a)块,总共有ceil(n/a)*ceil(m/a)块. 1 /* 2 ** CodeForces 1A Theatre Square 3 ** Created by Rayn @@ 2014/05/18 4 */ 5 #inclu

暴力/DP Codeforces Beta Round #22 (Div. 2 Only) B. Bargaining Table

题目传送门 1 /* 2 题意:求最大矩形(全0)的面积 3 暴力/dp:每对一个0查看它左下的最大矩形面积,更新ans 4 注意:是字符串,没用空格,好事多磨,WA了多少次才发现:( 5 详细解释:http://www.cnblogs.com/cszlg/p/3217478.html 6 */ 7 #include <cstdio> 8 #include <algorithm> 9 #include <cstring> 10 #include <cmath>

图论/暴力 Codeforces Beta Round #94 (Div. 2 Only) B. Students and Shoelaces

题目传送门 1 /* 2 图论/暴力:这是个连通的问题,每一次把所有度数为1的砍掉,把连接的点再砍掉,总之很神奇,不懂:) 3 */ 4 #include <cstdio> 5 #include <cstring> 6 #include <algorithm> 7 #include <cmath> 8 using namespace std; 9 10 const int MAXN = 1e2 + 10; 11 const int INF = 0x3f3f3

贪心+stack Codeforces Beta Round #5 C. Longest Regular Bracket Sequence

题目传送门 1 /* 2 题意:求最长括号匹配的长度和它的个数 3 贪心+stack:用栈存放最近的左括号的位置,若是有右括号匹配,则记录它们的长度,更新最大值,可以在O (n)解决 4 详细解释:http://blog.csdn.net/taoxin52/article/details/26012167 5 */ 6 #include <cstdio> 7 #include <algorithm> 8 #include <cstring> 9 #include <

BFS Codeforces Beta Round #94 (Div. 2 Only) C. Statues

题目传送门 1 /* 2 BFS:三维BFS,坐标再加上步数,能走一个点当这个地方在步数内不能落到.因为雕像最多8步就会全部下落, 3 只要撑过这个时间就能win,否则lose 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <queue> 8 #include <vector> 9 #include <cstring> 10 using namespace std; 11 1

水题 Codeforces Beta Round #70 (Div. 2) A. Haiku

题目传送门 1 /* 2 水题:三个字符串判断每个是否有相应的元音字母,YES/NO 3 下午网速巨慢:( 4 */ 5 #include <cstdio> 6 #include <cstring> 7 #include <string> 8 #include <iostream> 9 #include <algorithm> 10 #include <cmath> 11 using namespace std; 12 13 cons

Codeforces Beta Round#2

Codeforces Beta Round#2 http://codeforces.com/contest/2 A 模拟题 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 5 map<string,ll>mp; 6 struct sair{ 7 string str; 8 int id; 9 ll num; 10 }a[1005]; 11 12 bool cmp(sair a,sa