zoukankan      html  css  js  c++  java
  • POJ1008 1013 1207 2105 2499(全部水题)

    做了一天水题,挑几个还算凑合的发上来。

    POJ1008 Maya Calendar

    分析:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    
    using namespace std;
    
    char Haab[][10] = {"pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin", "mol",
        "chen", "yax", "zac", "ceh", "mac", "kankin", "muan", "pax", "koyab", "cumhu", "uayet"};
    
    char Tzo[][10] = {"imix", "ik", "akbal", "kan", "chicchan", "cimi", "manik", "lamat",
        "muluk", "ok", "chuen", "eb", "ben", "ix", "mem", "cib", "caban", "eznab", "canac", "ahau"};
    
    int main() {
        int year, day, cnt, month;
        char szmonth[20];
        int T;
    
        scanf("%d", &T);
    
        printf("%d
    ", T);
        for(int k=0; k<T; k++) {
            scanf("%d.%s%d", &day, szmonth, &year);
    
            for(int i=0; i<19; i++) if(strcmp(Haab[i], szmonth) == 0) month = i;
    
            cnt = year*365+month*20+day+1;
    
            int ty=0, td=0, tm=0;
    
            ty=(cnt-1+260)/260-1;
            tm=(cnt-1+20)%20;
            td=(cnt-1+13)%13+1;
    
            printf("%d %s %d
    ", td, Tzo[tm], ty);
        }
    
        return 0;
    }
    View Code

    POJ1013 Counterfeit Dollar

    分析:

    超级暴力:分别对A~L这12个字母枚举轻重两种情况。

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    
    using namespace std;
    
    char _left[5][20], _right[5][20], cond[5][20];
    
    int cmp(char s1[], char s2[], int k, int j) {
        /*
            * 用来比较天平的平衡
            * 右边up 返回 1
            * 平衡 返回 0
            * 右边down 返回 -1
        */
        int len = strlen(s1);
        int lef, rig;
        lef = rig = 0;
    
        for(int i=0; i<len; i++) {
            if(s1[i] == 'A'+k) lef += j;
            if(s2[i] == 'A'+k) rig += j;
        }
    
        if(lef < rig) return 1;
        else if(lef == rig) return 0;
        else return -1;
    }
    
    int main(){
        int T, i, c, j;
        scanf("%d", &T);
    
        while(T--) {
            for(i=0; i<3; i++) {
                scanf("%s %s %s", _left[i], _right[i], cond[i]);
            }
    
            for(i=0; i<12; i++) {   //分别枚举12个字母
                for(j=-1; j<=1; j++) {  //轻重两种情况
                    if(j==0) continue;
    
                    for(c=0; c<3; c++) {    //三组
                        int res = cmp(_left[c], _right[c], i, j);
                        if( ! ((res == 1 && cond[c][0] == 'u') ||
                           (res == 0 && cond[c][0] == 'e') ||
                           (res == -1 && cond[c][0] == 'd')))
                           break;
                    }
                    if(c >= 3) break;
                }
                if(c >= 3) break;
            }
    
            printf("%c is the counterfeit coin and it is ", i+'A');
            if(j == -1) printf("heavy.
    ");
            else printf("light.
    ");
        }
    
        return 0;
    }
    View Code

    POJ1207 The 3n + 1 problem

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    
    using namespace std;
    
    const int maxn =  100000+10;
    
    int hash[maxn];
    
    int get(int n) {
        if(!hash[n]) {
            int t = n;
            int cnt = 0;
            while(true) {
                cnt++;
                if(n == 1) return (hash[t] = cnt);
                if(n % 2 == 1) n = 3*n+1;
                else n = n/2;
            }
        }
        else return hash[n];
    }
    
    int main() {
        int a, b, n, m;
    
        memset(hash, 0, sizeof(hash));
    
        while(scanf("%d %d", &n, &m) == 2) {
            a = n, b = m;
            if(a > b) swap(a, b);
            int max_v = -1;
            for(int i=a; i<=b; i++) {
                if(max_v < get(i)) {
                    max_v = get(i);
                }
            }
    
            printf("%d %d %d
    ", n, m, max_v);
        }
    
        return 0;
    }
    View Code

    POJ2105 IP Address

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    
    using namespace std;
    
    const int maxn = 55;
    
    char s[maxn];
    
    int main() {
        int n;
        scanf("%d", &n);
    
        while(n--) {
            scanf("%s", s);
    
    
            for(int i=0; i<4; i++) {
                int ans = 0;
                for(int j=0; j<8; j++) {
                    ans += (s[i*8+j]-'0')*(1<<(7-j));
                }
                if(i == 0) printf("%d", ans);
                else printf(".%d", ans);
            }
            putchar('
    ');
        }
    
        return 0;
    }
    View Code

    POJ2499 Binary Tree

    分析:

    用减的话会超时的。用除省时间。

    #include <iostream>
    #include <cstdio>
    
    using namespace std;
    
    int main(){
        int n, a, b;
        int cnt1, cnt2;
        scanf("%d", &n);
        for(int kase=1; kase<=n; kase++) {
            cnt1 = cnt2 = 0;
            scanf("%d%d", &a, &b);
    
            while(a != b) {
                if(a > b) {
                    cnt1 += a/b;
                    a %= b;
                    if(a == 0) {
                        cnt1--; break;
                    }
                }
                else {
                    cnt2 += b/a;
                    b %= a;
                    if(b == 0) {
                        cnt2--; break;
                    }
                }
            }
    
            printf("Scenario #%d:
    ", kase);
            printf("%d %d
    
    ", cnt1, cnt2);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    Ubuntu 10.04安装google拼音输入法
    Ubuntu 10.04 编译Android 2.1源码
    Android make sdk 错误解决方案
    关于android内核从linux内核分支上除名
    odex打包为可用的apk程序
    取得当前屏幕的截图
    android设备作为视频监控客户端的思路
    政府网站群系统选型
    浅谈网站群的一代与二代技术
    我的2013
  • 原文地址:https://www.cnblogs.com/tanhehe/p/3231219.html
Copyright © 2011-2022 走看看