签到 2016.6.14

来源:互联网 发布:bpm测定软件 编辑:程序博客网 时间:2024/05/02 03:07

1、CodeForces 271A Beautiful Year

将四个位上的数取出来
判断是不是互不相等

#include <iostream>#include <cstdio>using namespace std;int main(){//    freopen("in.txt", "r", stdin);    int y;    while (cin>>y) {        while (1) {            ++y;            int a = y/1000;            int b = y%1000/100;            int c = y%100/10;            int d = y%10;            if (a!=b && a!=c && a!=d && b!=c && b!=d && c!=d) {                cout<<y<<endl;                break;            }        }    }    return 0;}

2、HDU 5655 CA Loves Stick

题意:
构成四边形的条件:最长边小于其余三条边的和

坑点1:假如有条长度为0的边的话,哪里来的四条边呢?

坑点2:其余三条边的和会爆longlong和unsigned long long,double的话精度不够

解题思路:
公式变形

#include <iostream>#include <cstdio>using namespace std;typedef unsigned long long ULL;int main(){//    freopen("in.txt", "r", stdin);    int T;    cin>>T;    ULL a[4];    while (T--) {        cin>>a[0]>>a[1]>>a[2]>>a[3];        for (int i=0; i<3; ++i) {            for (int j=i+1; j<4; ++j) {                if (a[i] < a[j]) {                    ULL t = a[i];                    a[i] = a[j];                    a[j] = t;                }            }        }        if (a[3] == 0) {            cout<<"No"<<endl;        } else if (a[0] < a[1] + a[2]) {            cout<<"Yes"<<endl;        } else if (a[0] > a[2] + a[1] && a[0]-a[1]-a[2] < a[3]) {            cout<<"Yes"<<endl;        } else {            cout<<"No"<<endl;        }    }    return 0;}

3、HDU 5660 jrMz and angles

题意:
给一个正n边形和正m边形
判断用这两个多边形的内角是否能组成360°

解题思路:
一:
暴力
二(官方解题报告):
不妨令n≤m。

如果n>6,由于所有角都大于120度且小于180度,也就是说,两个角一定不够,而三个角一定过多。因此一定无解;

当n≤6时,

如果n=3或n=4或n=6,那么显然只需要正n边形的角就可以了。

如果n=5,则已经有一个108度的角。
若这种角:

不取,则显然仅当m=6时有解;

取1个,则还差360−108=252(度),但是没有一个正m边形的内角的度数是252的约数;

取2个,则还差360−108×2=144(度),这恰好是正10边形的内角,
取3个,则还差360−108×3=36(度),也不可能满足;取大于3个也显然不可能。

因此得到结论:当n和m中至少有一个为3或4或6时,或者当nn和mm中一个等于5另一个等于10时,有解,否则无解,

时间复杂度为O(T)

#include <iostream>using namespace std;int main(){    int T;    while (cin>>T) {        while (T--) {            int n, m;            cin>>n>>m;            int Min = min(n, m);            int Max = max(n, m);            if (Min == 3 || Min == 4 || Min == 6 || Max == 6 || (Min == 5 && Max == 10)) {                cout<<"Yes"<<endl;            } else {                cout<<"No"<<endl;            }        }    }    return 0;}
#include <iostream>#include <cstdio>#include <cstring>using namespace std;int main(){//    freopen("in.txt", "r", stdin);    int T;    while (cin>>T) {        while (T--) {            int n, m;            cin>>n>>m;            double x = 180.0 - 360.0 / n;            double y = 180.0 - 360.0 / m;            int flag = 0;            for (int i=0; i<=360; ++i) {                if (flag == 1) {                    break;                }                for (int j=0; j<=360; ++j) {                    if (y*j > 360) {                        break;                    }                    if (x*i + y*j == 360) {                        flag = 1;                        cout<<"Yes"<<endl;                        break;                    }                }            }            if (flag == 0) {                cout<<"No"<<endl;            }        }    }    return 0;}

4、ccf历届题-201512-2_消除类游戏

题意:
消除类游戏的规则,某一行或列有连续的相同元素的个数≥3则进行消除

解题思路:
标记完以后再进行消除

#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int maxn = 30 + 5;int Map[maxn][maxn];bool vis[maxn][maxn];int main(){//    freopen("in.txt", "r", stdin);    memset(vis, false, sizeof(vis));    int n, m;    cin>>n>>m;    for (int i=0; i<n; ++i) {        for (int j=0; j<m; ++j) {            cin>>Map[i][j];        }    }    for (int i=0; i<n; ++i) {        for (int j=0; j<m; ++j) {            int Count = 1;            for (int k=i+1; k<n&&Map[i][j]==Map[k][j]; ++k) {                ++Count;            }            if (Count >= 3) {                for (int k=i; k<i+Count; ++k) {                    vis[k][j] = true;                }            }            Count = 1;            for (int k=j+1; k<m&&Map[i][j]==Map[i][k]; ++k) {                ++Count;            }            if (Count >= 3) {                for (int k=j; k<j+Count; ++k) {                    vis[i][k] = true;                }            }        }    }    for (int i=0; i<n; ++i) {        for (int j=0; j<m-1; ++j) {            if (vis[i][j]) {                Map[i][j] = 0;            }            cout<<Map[i][j]<<" ";        }        if (vis[i][m-1]) {            Map[i][m-1] = 0;        }        cout<<Map[i][m-1]<<endl;    }    return 0;}

5、Google Code Jam Qualification Round 2016_A Counting Sheep

Problem

Bleatrix Trotter the sheep has devised a strategy that helps her fall asleep faster. First, she picks a number N. Then she starts naming N, 2 × N, 3 × N, and so on. Whenever she names a number, she thinks about all of the digits in that number. She keeps track of which digits (0, 1, 2, 3, 4, 5, 6, 7, 8, and 9) she has seen at least once so far as part of any number she has named. Once she has seen each of the ten digits at least once, she will fall asleep.

Bleatrix must start with N and must always name (i + 1) × N directly after i × N. For example, suppose that Bleatrix picks N = 1692. She would count as follows:

N = 1692. Now she has seen the digits 1, 2, 6, and 9.2N = 3384. Now she has seen the digits 1, 2, 3, 4, 6, 8, and 9.3N = 5076. Now she has seen all ten digits, and falls asleep.

What is the last number that she will name before falling asleep? If she will count forever, print INSOMNIA instead.
Input

The first line of the input gives the number of test cases, T. T test cases follow. Each consists of one line with a single integer N, the number Bleatrix has chosen.
Output

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the last number that Bleatrix will name before falling asleep, according to the rules described in the statement.
Limits

1 ≤ T ≤ 100.

0 ≤ N ≤ 10^6.

Sample

Input

5
0
1
2
11
1692

Output

Case #1: INSOMNIA
Case #2: 10
Case #3: 90
Case #4: 110
Case #5: 5076

In Case #1, since 2 × 0 = 0, 3 × 0 = 0, and so on, Bleatrix will never see any digit other than 0, and so she will count forever and never fall asleep. Poor sheep!

In Case #2, Bleatrix will name 1, 2, 3, 4, 5, 6, 7, 8, 9, 10. The 0 will be the last digit needed, and so she will fall asleep after 10.

In Case #3, Bleatrix will name 2, 4, 6… and so on. She will not see the digit 9 in any number until 90, at which point she will fall asleep. By that point, she will have already seen the digits 0, 1, 2, 3, 4, 5, 6, 7, and 8, which will have appeared for the first time in the numbers 10, 10, 2, 30, 4, 50, 6, 70, and 8, respectively.

In Case #4, Bleatrix will name 11, 22, 33, 44, 55, 66, 77, 88, 99, 110 and then fall asleep.

Case #5 is the one described in the problem statement. Note that it would only show up in the Large dataset, and not in the Small dataset.

题意:
给一个N(0 ≤ N ≤ 10^6),然后用它去乘1,2,3,4…,每次把乘积的每一位上的数取出来,如果乘到n时0-9每个数都至少被取出来一次,那么输出N*n,不再继续乘

解题思路:
特判0

#include <iostream>#include <cstdio>#include <cstring>using namespace std;bool vis[10];int main(){//    freopen("A-small-attempt2.in", "r", stdin);//    freopen("out.out", "w", stdout);    int T;    cin>>T;    int Case = 0;    while (T--) {        memset(vis, false, sizeof(vis));        ++Case;        int N;        cin>>N;        if (N == 0) {            printf("Case #%d: INSOMNIA\n", Case);        } else {            int Count = 0;            int i = 1;            while (Count < 10) {                int t = N*i;                while (t) {                    if (!vis[t%10]) {                        vis[t%10] = true;                        ++Count;                    }                    t /= 10;                }                ++i;            }            int ans = N *(i-1);            printf("Case #%d: %d\n", Case, ans);        }    }    return 0;}

6、NUC_ 第11届校赛_G 剪纸片

解题思路:
求最大公约数

#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <map>#include <queue>using namespace std;const int INF = 0x3f3f3f3f;int gcd(int a, int b);int main(){    int N;    int A, B;    scanf("%d", &N);    int Case = 0;    while (N--) {        scanf("%d%d", &A, &B);        ++Case;        if (A < B) {            int t = A;            A = B;            B = t;        }        int g = gcd(A, B);        printf("case %d: ", Case);        printf("%d\n", A/g * B/g);    }    return 0;}int gcd(int a, int b){    return (a%b == 0) ? b : gcd(b, a%b);}

7、团体程序设计天梯赛-练习集 L2-009 抢红包

#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <vector>#include <cmath>using namespace std;const int maxn = 1e4 + 10;struct Node {    int num, price;    int Count;};Node node[maxn];int cmp_num(const void* a, const void* b);int main(){    int N;    scanf("%d", &N);    memset(node, 0, sizeof(node));    for (int i = 1; i <= N; ++i) {        node[i].num = i;    }    for (int i = 1; i <= N; ++i) {        int K;        scanf("%d", &K);        while (K--) {            int a, b;            scanf("%d%d", &a, &b);            node[i].price -= b;            node[a].price += b;            node[a].Count += 1;        }    }    qsort(node+1, N, sizeof(node[0]), cmp_num);    for (int i = 1; i <= N; ++i) {        double t = node[i].price / 100.0;        printf("%d %.2lf\n", node[i].num, t);    }    return 0;}int cmp_num(const void* a, const void* b){    Node* x = (Node*)a;    Node* y = (Node*)b;    if (x->price == y->price && x->Count == y->Count) {        return (x->num - y->num) >0 ? 1 : -1;    }    if (x->price == y->price) {        return (x->Count - y->Count) > 0 ? -1 : 1;    }    return (x->price - y->price) > 0 ? -1 : 1;}

8、团体程序设计天梯赛-练习集 L1-017 到底有多二

#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <vector>#include <cmath>using namespace std;const int INF = 0x7fffffff;const int mod = 1e9 + 7;const int maxn = 50 + 10;char N[maxn];int main(){#ifdef __AiR_H    freopen("in.txt", "r", stdin);#endif // __AiR_H    gets(N);    int len = strlen(N);    int _2_num = 0;    int num_len = len;    double negtive = 1.0;    double Even = 1.0;    if (N[0] == '-') {        --num_len;        negtive = 1.5;    }    int t = N[len-1] - '0';    if ((t&1) == 0) {        Even = 2.0;    }    for (int i = 0; i < len; ++i) {        if (N[i] == '2') {            ++_2_num;        }    }    double ans_t = _2_num * negtive * Even * 100.0 / num_len ;    printf("%.2lf%%\n", ans_t);    return 0;}

9、CodeForces_1B Spreadsheets

题意:
转换格式输出

解题思路:
格式判断以后求出行和列,输出时以不同格式输出

我:
刚开始竟然以为排序…

#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>#include <queue>#include <vector>#include <stack>#include <map>#include <cmath>#include <cctype>using namespace std;typedef long long ll;typedef unsigned long long ull;typedef unsigned int uint;const int mod = 1e9 + 7;const int INF = 0x7fffffff;const int maxn = 1e5 + 10;struct Node {    char s[20];    int row, column;    bool RXCY;};Node node;int main(){#ifdef __AiR_H    freopen("in.txt", "r", stdin);#endif // __AiR_H    int n;    scanf("%d", &n);    for (int i = 0; i < n; ++i) {        scanf("%s", node.s);        int len = strlen(node.s);        node.RXCY = false;        for (int j = len-1; j >= 0; --j) {            if (j != 0 && node.s[j] == 'C' && isdigit(node.s[j-1]) && isdigit(node.s[j+1])) {                node.RXCY = true;                break;            }        }        node.row = 0; node.column = 0;        if (node.RXCY) {            int pos = 1;            while (isdigit(node.s[pos])) {                node.row = node.row*10 + node.s[pos] - '0';                ++pos;            }            ++pos;            while (pos < len) {                node.column = node.column*10 + node.s[pos] - '0';                ++pos;            }        } else {            for (int j = 0; j < len; ++j) {                if (isalpha(node.s[j])) {                    node.column = node.column * 26 + (node.s[j] - 'A' + 1);                } else {                    node.row = node.row * 10 + node.s[j] - '0';                }            }        }        if (node.RXCY) {            stack<char> S;            while (node.column) {                node.column -= 1;                char t = (node.column % 26) + 'A';                node.column /= 26;                S.push(t);            }            while (!S.empty()) {                printf("%c", S.top());                S.pop();            }            printf("%d\n", node.row);        } else {            printf("R%dC%d\n", node.row, node.column);        }    }    return 0;}

10、CodeForces_678C Joty and Chocolate

题意:
有下标为 1 ~ n 的 n 个瓷砖,现在要给它们涂上颜色
若下标只能被 a 整除,那么将涂红色,只能被 b 整除,涂上蓝色,同时可以被 a 和 b 整除,可以涂红色,也可以涂蓝色
如果瓷砖被涂为红色,将获得 p 个巧克力,涂为蓝色,获得 q 个巧克力
问怎样涂才可以获得最多的巧克力

解题思路:
同时可以被 a,b 整除的就是求 lcm
1 ~ n 可以被它们整除的个数分别是 n/a、n/b、n/lcm
只要将下标能被 lcm 整除的涂上获得巧克力多的颜色就可以了

#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>#include <queue>#include <vector>#include <stack>#include <map>#include <cmath>#include <cctype>using namespace std;typedef long long ll;typedef unsigned long long ull;typedef unsigned int uint;const int mod = 1e9 + 7;const int INF = 0x7fffffff;ull n;ull gcd(ull a, ull b);int main(){#ifdef __AiR_H    freopen("in.txt", "r", stdin);#endif // __AiR_H    ull a, b, p, q;    scanf("%I64d%I64d%I64d%I64d%I64d", &n, &a, &b, &p, &q);    ull Max = max(p, q);    ull lcm = a / gcd(a, b) * b;    ull ans_a = n/a, ans_b = n/b, ans_c = n/lcm;    ull ans = (ans_a - ans_c) * p + (ans_b - ans_c) * q + ans_c * Max;    printf("%I64d\n", ans);    return 0;}ull gcd(ull a, ull b){    return (a%b == 0) ? b : gcd(b, a%b);}
0 0
原创粉丝点击