`
200830740306
  • 浏览: 106363 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

poj1013

阅读更多
package middle;


import java.io.BufferedInputStream;
import java.util.Scanner;

/**
 * 12硬币找出一个假的,并且判出轻重
 *poj1013参照网上的枚举法
 * @author NC
 */
public class Poj1013 {

    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedInputStream(System.in));
        if (scan.hasNext()) {
            int n = Integer.parseInt(scan.nextLine().trim());
            for (int i = 0; i < n; i++) {
                boolean[] real = {false, false, false, false, false, false, false, false, false, false, false, false};
                int[] hy = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
                String[] s1 = scan.nextLine().trim().split(" ");
                String[] s2 = scan.nextLine().trim().split(" ");
                String[] s3 = scan.nextLine().trim().split(" ");
                char[] c11 = s1[0].toCharArray();
                char[] c12 = s1[1].toCharArray();
                char[] c21 = s2[0].toCharArray();
                char[] c22 = s2[1].toCharArray();
                char[] c31 = s3[0].toCharArray();
                char[] c32 = s3[1].toCharArray();
                if (s1[2].equals("even")) {
                    for (int j = 0; j < c11.length; j++) {
                        real[c11[j] - 'A'] = true;
                    }
                    for (int j = 0; j < c12.length; j++) {
                        real[c12[j] - 'A'] = true;
                    }
                }
                if (s2[2].equals("even")) {
                    for (int j = 0; j < c21.length; j++) {
                        real[c21[j] - 'A'] = true;
                    }
                    for (int j = 0; j < c22.length; j++) {
                        real[c22[j] - 'A'] = true;
                    }
                }
                if (s3[2].equals("even")) {
                    for (int j = 0; j < c31.length; j++) {
                        real[c31[j] - 'A'] = true;
                    }
                    for (int j = 0; j < c32.length; j++) {
                        real[c32[j] - 'A'] = true;
                    }
                }
                if (s1[2].equals("up")) {
                    for (int j = 0; j < c11.length; j++) {
                        hy[c11[j] - 'A']++;
                    }
                    for (int j = 0; j < c12.length; j++) {
                        hy[c12[j] - 'A']--;
                    }
                }
                if (s2[2].equals("up")) {
                    for (int j = 0; j < c21.length; j++) {
                        hy[c21[j] - 'A']++;
                    }
                    for (int j = 0; j < c22.length; j++) {
                        hy[c22[j] - 'A']--;
                    }
                }
                if (s3[2].equals("up")) {
                    for (int j = 0; j < c31.length; j++) {
                        hy[c31[j] - 'A']++;
                    }
                    for (int j = 0; j < c32.length; j++) {
                        hy[c32[j] - 'A']--;
                    }
                }
                if (s1[2].equals("down")) {
                    for (int j = 0; j < c11.length; j++) {
                        hy[c11[j] - 'A']--;
                    }
                    for (int j = 0; j < c12.length; j++) {
                        hy[c12[j] - 'A']++;
                    }
                }
                if (s2[2].equals("down")) {
                    for (int j = 0; j < c21.length; j++) {
                        hy[c21[j] - 'A']--;
                    }
                    for (int j = 0; j < c22.length; j++) {
                        hy[c22[j] - 'A']++;
                    }
                }
                if (s3[2].equals("down")) {
                    for (int j = 0; j < c31.length; j++) {
                        hy[c31[j] - 'A']--;
                    }
                    for (int j = 0; j < c32.length; j++) {
                        hy[c32[j] - 'A']++;
                    }
                }
                int m = 0;
                for (int k = 0; k < real.length; k++) {
                    if (!real[k]) {
                        int max = Math.abs(hy[k]);
                        m = k;
                        for (int j = k + 1; j < hy.length; j++) {
                            if (Math.abs(hy[j]) > max && !real[j]) {
                                max = Math.abs(hy[j]);
                                m = j;
                            }
                        }
                        break;
                    }
                }
                char key = (char) ('A' + m);
                if (hy[m] > 0) {
                    System.out.println(key + " is the counterfeit coin and it is heavy.");
                } else {
                    System.out.println(key + " is the counterfeit coin and it is light.");
                }
            }
        }
    }
}


分享到:
评论

相关推荐

    POJ1013 C解法

    NULL 博文链接:https://taojianrong.iteye.com/blog/1756785

    POJ1013-Counterfeit Dollar

    北大POJ1013-Counterfeit Dollar 解题报告+AC代码

    ACM 比赛 POJ的训练计划,,,非常不错,关键在于坚持

    第十四类是模拟,涵盖了至少五个题目,包括 1029 和 1013 等题目。 第十五类是数学,涵盖了至少四个题目,包括 2249 和 1056 等题目。 此外,该计划还提供了一些水题供选手练习和提高自信心,如 POJ3299、POJ2159 ...

    POJ PKU 必做题+部分难题1001-2500

    1011,1012,1013,1014,1015,1017,1026,1028,1032,1035,1041,1046,1129 1149 1154 1165 1182 1185 1190 1191 1201 1251 1273 1275 1276 1286 1322 1338 1363 1364 1401 1456 1459 1564 1579 1637 1657 1658 ...

    poj100题解。具体题号见说明

    1000 1002 1003 1004 1005 1006 1007 1008 1011 1012 1013 1019 1028 1045 1046 1068 1080 1088 1163 1207 1218 1256 1298 1299 1316 1326 1401 1455 1477 1488 1503 1504 1517 1519 1547 1552 1565 1579 1607 1656 ...

    acm poj 源代码

    1001 1002 1003 1004 1005 1006 1007 1008 1011 1012 1013 1014 1015 1017 1018 1019 1028 1032 1042 1046 1050 1061 1065 1066 1067 1077 1080 1083 1088 1094 1111 1125 1135 1141 1157 1160 1161 1163 1166 1170 ...

    poj pku 解题报告

    1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1011 1012 1013 1014 1015 1017 1018 1019 1028 1032 1035 1040 1042 1045 1046 1047 1050 1056 1061 1062 1063 1065 1067 1068 1080 1083 1088 1089 1091 1094 ...

    poj135道题的代码

    1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1011 1012 1013 1014 1018 1019 1028 1032 1040 1042 1045 1046 1047 1050 1056 1061 1062 1063 1065 1067 1068 1083 1088 1102 1113 1118 1126 1141 1142 1157 ...

    PKU源码。。。。。

    PKU,POJ共301题源代码。1001 1002 1003 1004 1005 1006 1007 1008 1011 1012 1013 1014 1015 1017 1018 1019 1028 1032 1042 1046 1050 1061 1065

    acm_problems:刷题!!!

    #POJ 题集 数论 欧几里得/拓展欧几里得算法 1006 1061 搜索 普通搜索 1062, 1088, 2386 剪枝优化 1011 动态规划 背包 1014 高精度 加减乘除 1001 巧妙处理 思维处理 1852 模拟 1017 简单题 水题 1004 1007 1008 枚举...

Global site tag (gtag.js) - Google Analytics