Codeforces Round #347 (Div. 2) (练习)
题意:找到[a, b]的最大公约数;
思路:相同时为本身,不同时为1.
套路:碰到水题别想太多;
猜想:两个相邻数,必有一奇一偶,如果偶数有因子3或者其他,奇数可不可能有相同的呢?
枚举一些数后发现没有,出现的奇数全是素数。
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <time.h>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <set> #define c_false ios_base::sync_with_stdio(false); cin.tie(0)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define zero_(x,y) memset(x , y , sizeof(x))
#define zero(x) memset(x , 0 , sizeof(x))
#define MAX(x) memset(x , 0x3f ,sizeof(x))
#define swa(x,y) {LL s;s=x;x=y;y=s;}
using namespace std ;
typedef long long LL;
const int N = ; char n[N], m[N]; int main(){
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
//ios_base::sync_with_stdio(false); cin.tie(0);
scanf("%s%s", n, m);
string n1, m1;
n1 = n; m1 = m;
if(n1 == m1) printf("%s\n", n);
else printf("1\n");
return ;
}
题意:找到一些数,满足以下等式 :?+ ? + ?- ? = n
思路:1) 可以将+ 和 - 分开计算,+ sum1, - sum2 然后将sum1 与sum 2 分派下去,
2) (注意到数是可以重复的) 先将所有数设置为1, 然后 ans > n, - 加1,否则 + 加1;
1 #include <iostream>
2 #include <algorithm>
3 #include <stdlib.h>
4 #include <time.h>
5 #include <cmath>
6 #include <cstdio>
7 #include <string>
8 #include <cstring>
9 #include <vector>
10 #include <queue>
11 #include <stack>
12 #include <set>
13
14 #define c_false ios_base::sync_with_stdio(false); cin.tie(0)
15 #define INF 0x3f3f3f3f
16 #define INFL 0x3f3f3f3f3f3f3f3f
17 #define zero_(x,y) memset(x , y , sizeof(x))
18 #define zero(x) memset(x , 0 , sizeof(x))
19 #define MAX(x) memset(x , 0x3f ,sizeof(x))
20 #define swa(x,y) {LL s;s=x;x=y;y=s;}
21 using namespace std ;
22 typedef long long LL;
23 const int N = 205;
24
25 int num1[N], num2[N];
26 char s[2];
27
28 int main(){
29 //freopen("in.txt","r",stdin);
30 //freopen("out.txt","w",stdout);
31 //ios_base::sync_with_stdio(false); cin.tie(0);
32 zero(num1);
33 zero(num2);
34 scanf("%s", s);
35 scanf("%s", s);
36 int p = 1, q = 0, k = 1;
37 num1[1] = 1;
38 while(s[0] != '='){
39 if(s[0] == '+'){
40 num1[++k] = 1;
41 p++;
42 }
43 if(s[0] == '-'){
44 num1[++k] = -1;
45 q++;
46 }
47 scanf("%s", s);
48 scanf("%s", s);
49 }
50 int n;
51 scanf("%d", &n);
52 for(int i = 1; i <= k; i++){
53 num2[i] = 1;
54 }
55 int sum = p - q;
56 for(int i = 1; i <= k; i++){
57 while(sum < n && num1[i] == 1 && num2[i] < n){
58 num2[i]++, sum++;
59 }
60 while(sum > n && num1[i] == -1 && num2[i] < n){
61 num2[i]++, sum--;
62 }
63 }
64 if(sum != n){
65 printf("Impossible\n");
66 return 0;
67 }
68 printf("Possible\n");
69 printf("%d ", num2[1]);
70 for(int i = 2; i <= k; i++){
71 if(num1[i] == 1) printf("+ ");
72 else if(num1[i] == -1) printf("- ");
73 printf("%d ", num2[i]);
74 }
75 printf("= %d\n", n);
76 return 0;
77 }
C:
题意:求尾号代表的年份
思路:贪心法, 主要是如何通过后缀找到原年份。
区间的长度为后缀字符的个数^10
可以先预处理区间长度再找后缀字符的位置;
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <time.h>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <set> #define c_false ios_base::sync_with_stdio(false); cin.tie(0)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define zero_(x,y) memset(x , y , sizeof(x))
#define zero(x) memset(x , 0 , sizeof(x))
#define MAX(x) memset(x , 0x3f ,sizeof(x))
#define swa(x,y) {LL s;s=x;x=y;y=s;}
using namespace std;
typedef long long LL;
const int N = ; LL a[], a1[];
char b[]; int Solve(){
int len = strlen(b);
LL num = ;
for(int i = ; i < len; i++){
num *= ;
num += b[i] - '';
}
for(int i = ; i < ; i++){
int number = num + (LL)i * a1[len-];
if(number >= a[len-] && number < a[len - ]){
printf("%d\n", number);
return ;
}
}
return ;
} int main(){
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
//ios_base::sync_with_stdio(false); cin.tie(0);
int n, k = ;
a[] = ;
a1[] = ;
//设置首位置
for(int i = ; i < ; i++){
k *= ;
a[i] = a[i-] + k;
a1[i] = k;
}
scanf("%d", &n);
while(n--){
scanf("%s", b);
//printf("%s\n", b);
Solve();
}
return ;
}
D:
题意:将一些点翻转过来,得到所有边都相同颜色的图
思路:暴力美学,dfs搜索
Codeforces Round #347 (Div. 2) (练习)的更多相关文章
- Codeforces Round #347 (Div. 2) C. International Olympiad 找规律
题目链接: http://codeforces.com/contest/664/problem/C 题解: 这题最关键的规律在于一位的有1989-1998(9-8),两位的有1999-2098(99- ...
- Codeforces Round #347 (Div. 2) B. Rebus
题目链接: http://codeforces.com/contest/664/problem/B 题意: 给你一个等式,把等式左边的问号用1到n(n为等式右边的数)的数填好,使得等式成立 题解: 贪 ...
- Codeforces Round #347 (Div.2)_B. Rebus
题目链接:http://codeforces.com/contest/664/problem/B B. Rebus time limit per test 1 second memory limit ...
- Codeforces Round #347 (Div.2)_A. Complicated GCD
题目链接:http://codeforces.com/contest/664/problem/A A. Complicated GCD time limit per test 1 second mem ...
- Codeforces Round #347 (Div. 2)
unrating的一场CF A - Complicated GCD #include <bits/stdc++.h> const int N = 1e5 + 5; char a[105], ...
- codeforces Round #347 (Div. 2) C - International Olympiad
思路:从后往前一位一位的模拟,每次判断一下当前枚举的数是否之间枚举过了.或者当前枚举数过小,小于1989. #include<cstdio> #include<cstring> ...
- Codeforces Round #347 (Div. 2) A
Description Greatest common divisor GCD(a, b) of two positive integers a and b is equal to the bigge ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
随机推荐
- Apache Server 添加虚拟主机(Virtual Host )
当前许多虚拟服务器如阿里云的ECS服务器,都提供各式各样的虚拟机,常见的有Linux.Windows等,如果我们使用了Apache Server作为虚拟机的Web服务器,并且我们希望多个web应用程序 ...
- iOS点击状态栏返回顶部问题。
在适配点击状态栏返回顶部的时候,有一个viewcontroller里面有一个UITableView和一个UITextView,UITableView的cell里面没有UIScrollView和UITa ...
- python安装tkinter
python2安装tkinter sudo apt-get install python-tk python3 安装tkinter sudo apt-get install python3-tk
- c++的默认构造函数 VS 深拷贝(值拷贝) 与 浅拷贝(位拷贝)
C++默认为类生成了四个缺省函数: A(void); // 缺省的无参数构造函数 A(const A &a); // 缺省的拷贝构造函数 ~A(void); // 缺省的析构函数 A & ...
- 十.oc内存管理
引用百度百科图 栈(stack)又名堆栈. 栈定义:栈是限定仅在表头进行插入和删除操作的线性表(有序).(又称:后进先出表) (动态)数据展示存储的地方.(举例:升降电梯)特点:先进后出(FILO—F ...
- DateTime.Compare用法
DateTime.Compare(t1,t2)比较两个日期大小,排前面的小,排在后面的大,比如:2011-2-1就小于2012-3-2返回值小于零: t1 小于 t2. 返回值等于零 : t1 等于 ...
- aspx页面,中文乱码解决方案
由于文件编码方式编码方式不统一出现样式中文乱码解决方案: 今天碰到的问题:页面字体样式设置的'微软雅黑',可页面没引用.我调试看到样式出现中文乱码了 这种问题,就需要转换文件的编码方式,如下两步即可解 ...
- 第九周PSP
工作周期:11.10-11.17 本周PSP: C类型 C内容 S开始时间 ST结束时间 I中断时间 T净时间(分) 文档 写随笔(PSP) 19:00min 22:00min 30min 90mi ...
- iOS实现类似于歌词进度效果
先看效果 这里关键的地方在于镂空文字的实现,可以用UILabel的drawRect方法. .h文件 @interface HollowLabel : UILabel @end .m文件 @interf ...
- 大三CS狗一点想法
本文非技术文 十点半游戏的代码大概完成了1/3,想到今晚提早验收完汇编实验,还是副院长亲自验的,似乎很看好我的样子,然后问我的方向,导师和参加的项目.聊了几句后结束了对话,不禁又引发了我的一些思考. ...