A:

题意:找到[a, b]的最大公约数;

思路:相同时为本身,不同时为1.

套路:碰到水题别想太多;

猜想:两个相邻数,必有一奇一偶,如果偶数有因子3或者其他,奇数可不可能有相同的呢?

   枚举一些数后发现没有,出现的奇数全是素数。

 

 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 char n[N], m[N];
26 
27 int main(){
28     //freopen("in.txt","r",stdin);
29     //freopen("out.txt","w",stdout);
30     //ios_base::sync_with_stdio(false); cin.tie(0);
31     scanf("%s%s", n, m);
32     string n1, m1;
33     n1 = n; m1 = m;
34     if(n1 == m1) printf("%s\n", n);
35     else printf("1\n");
36     return 0;
37 }
View Code

 

B:

题意:找到一些数,满足以下等式 :?+ ? + ?- ? = 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 }
View Code

 

C:

题意:求尾号代表的年份

思路:贪心法, 主要是如何通过后缀找到原年份。

        区间的长度为后缀字符的个数^10

   可以先预处理区间长度再找后缀字符的位置;

 

 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 LL  a[30], a1[30];
26 char b[20];
27 
28 int Solve(){
29     int len = strlen(b);
30     LL num = 0;
31     for(int i = 4; i < len; i++){
32         num *= 10;
33         num += b[i] - '0';
34     }
35     for(int i = 0; i < 300; i++){
36         int number = num + (LL)i * a1[len-4];
37         if(number >= a[len-5] && number < a[len - 4]){
38             printf("%d\n", number);
39             return 0;
40         }
41     }
42     return 0;
43 }
44 
45 int main(){
46     //freopen("in.txt","r",stdin);
47     //freopen("out.txt","w",stdout);
48     //ios_base::sync_with_stdio(false); cin.tie(0);
49     int n, k = 1;
50     a[0] = 1989;
51     a1[0] = 1;
52     //设置首位置
53     for(int i = 1; i < 15; i++){
54         k *= 10;
55         a[i] = a[i-1] + k;
56         a1[i] = k;
57     }
58     scanf("%d", &n);
59     while(n--){
60         scanf("%s", b);
61         //printf("%s\n", b);
62         Solve();
63     }
64     return 0;
65 }
View Code

 

D:

 题意:将一些点翻转过来,得到所有边都相同颜色的图

 思路:暴力美学,dfs搜索

posted on 2016-05-10 15:22  yoyo_sincerely  阅读(338)  评论(0编辑  收藏  举报