1. 程式人生 > >POJ 1013 小水題 暴力模擬

POJ 1013 小水題 暴力模擬

Counterfeit Dollar
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 35774 Accepted: 11390

Description

Sally Jones has a dozen Voyageur silver dollars. However, only eleven of the coins are true silver dollars; one coin is counterfeit even though its color and size make it indistinguishable from the real silver dollars. The counterfeit coin has a different weight from the other coins but Sally does not know if it is heavier or lighter than the real coins.
Happily, Sally has a friend who loans her a very accurate balance scale. The friend will permit Sally three weighings to find the counterfeit coin. For instance, if Sally weighs two coins against each other and the scales balance then she knows these two coins are true. Now if Sally weighs
one of the true coins against a third coin and the scales do not balance then Sally knows the third coin is counterfeit and she can tell whether it is light or heavy depending on whether the balance on which it is placed goes up or down, respectively.
By choosing her weighings carefully, Sally is able to ensure that she will find the counterfeit coin with exactly three weighings.

Input

The first line of input is an integer n (n > 0) specifying the number of cases to follow. Each case consists of three lines of input, one for each weighing. Sally has identified each of the coins with the letters A--L. Information on a weighing will be given by two strings of letters and then one of the words ``up'', ``down'', or ``even''. The first string of letters will represent the coins on the left balance; the second string, the coins on the right balance. (Sally will always place the same number of coins on the right balance as on the left balance.) The word in the third position will tell whether the right side of the balance goes up, down, or remains even.

Output

For each case, the output will identify the counterfeit coin by its letter and tell whether it is heavy or light. The solution will always be uniquely determined.

Sample Input

1 
ABCD EFGH even 
ABCI EFJK up 
ABIJ EFGH even 

Sample Output

K is the counterfeit coin and it is light. 

Source

East Central North America 1998



題意 :
 有12個硬幣 有一個是假的 比其他的或輕或重     分別標記為A到L
然後輸入cas 有個cas組資料
每組輸入3行 每行3個字串 第一個表示當時天平上左邊有哪幾個字元  第二個是右邊 2邊個數一樣 但是不一定有幾個    之後第三個字串描述左邊是比右邊大小還是相等
問你  哪一個硬幣是假的  假的相對於真的是清還是重        
保證有解

思路:暴力模擬 暴力哪一個是假的  總共只有12個  很好暴力

 
#include<stdio.h>
#include<string.h>
int a[100];
char s[3][3][20];
int  solve()
{
    int i,j,k,len,n1,n2;
    for(k=0;k<3;k++)
    {
        n1=0;n2=0;
        len=strlen(s[k][0]);
        for(i=0;i<len;i++)
            n1+=a[s[k][0][i]-'A'];
        for(i=0;i<len;i++)
            n2+=a[s[k][1][i]-'A'];
        if(strcmp(s[k][2],"even")==0)
            if(n1!=n2) break;
        if(strcmp(s[k][2],"up")==0)
            if(n1<=n2) break;
        if(strcmp(s[k][2],"down")==0)
            if(n1>=n2) break;
    }
    if(k==3) return 1;
    return 0;
}
int main()
{
    int cas,i,j,flag;
    scanf("%d",&cas);
    while(cas--)
    {
        flag=0;
        for(i=0;i<3;i++)
            for(j=0;j<3;j++)
               scanf("%s",s[i][j]);
        for(i=0;i<12;i++) a[i]=2;
        for(i=0;i<12;i++)
        {
             a[i]=1;
             if(solve())
             {
                 flag=1;
                 printf("%c is the counterfeit coin and it is light.\n",i+'A');
             }
             if(flag) break;
             a[i]=2;
        }
        if(flag) continue;
        for(i=0;i<12;i++) a[i]=1;
        for(i=0;i<12;i++)
        {
             a[i]=2;
             if(solve())
             {
                 flag=1;
                 printf("%c is the counterfeit coin and it is heavy.\n",i+'A');
             }
             if(flag) break;
             a[i]=1;
        }
    }
    return 0;
}


相關推薦

POJ 1013 暴力模擬

Counterfeit Dollar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 35774 Accepted: 11390 Description Sally Jones has a doz

POJ - 3090 gcd

+= div poj 打表 turn logs 水題 -m bool 大概題意就是求\(1 \le i,j \le n\)的\(gcd(i,j) = 1\)的個數+2(對於0的特判) 正解應該是歐拉函數或者高逼格的莫比烏斯反演 但數據實在太水直接打表算了 /*H E A D

Crashing Robots(模擬)

nes 純粹 rst finall gpo without diameter als tar 1020: Crashing Robots 時間限制(普通/Java):1000MS/10000MS 內存限制:65536KByte 總提交: 207

模擬,但仍需細心,多考慮

== stream clas axis nbsp space sin clu 水題 //http://codeforces.com/contest/1065/problem/B#include <iostream> #include <cmath>

2018.10.28 洛谷 進化の模擬

傳送門 T 1 T1 T1一直過不了導致心態爆炸

The Triangle POJ - 1163 (dp)

dp基礎的不能再基礎的題 #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <string> #inclu

【HihoCoder - 1880】地鐵環線 (字首和,模擬

題幹: H市有一環線地鐵,一共包含N站,編號1~N。正向行駛的地鐵會按1 -> 2 -> 3 -> ... -> N -> 1的方向行駛,反向會按1 -> N -> N-1 -> ... -> 3 -> 2 -> 1的方向行駛

*【CodeForces - 1088 ABC】套比賽,AB模擬C構造D互動

A. Input The only line contains the integer xx (1≤x≤100)(1≤x≤100). Output You should output two integers aa and 

【UVA - 11292】Dragon of Loowater (貪心,模擬,twopointer雙指標)

題幹: 題目大意: n條惡龍,m個勇士,用勇士來殺惡龍。一個勇士只能殺一個惡龍。而且勇士只能殺直徑不超過自己能力值的惡龍。每個勇士需要支付能力值一樣的金幣。問殺掉所有惡龍需要花費的最少金幣。 解題報告:    twopointer排序後從頭到尾掃一遍就行了。

20161108的考試】腦洞模擬

…………我……今天……有毒2333 今天應該是完完全全的noip難度【應該還簡單一點? ……大概是真的沒有oier應有的直覺QAQ T2……好吧我是題看錯了看成了神題感覺完全無法做2333 ……要說今天崩在哪兒了…………大概是哪兒都崩了【 T2應該以前見過,可能是初中來蹭

codeforces 158B Taxi(貪心

time limit per test 3 seconds memory limit per test 256 megabytes input standard input outp

poj 3111 二分

題意:有n個物品的重量和價值分別是w[i]和v[i],從中選出K個物品使得單位重量的價值最大 貪心的反例是顯然的,nyoj的樣例就是 本題是個二分的很好例子,可以理解成二分得到一個閾值,然後判斷是否夠k個,以此得到最優解,而這個正確性也是顯然的 #include <

HDU 1049 青蛙爬進 (_模擬

Problem Description An inch worm is at the bottom of a well n inches deep. It has enough energy to climb u inches every minute, but the

【CodeForces - 1200A】Hotelier(模擬

Hotelier 直接翻譯了 Descriptions Amugae的酒店由10人組成10客房。房間從0開始編號0到99 從左到右。 酒店有兩個入口 - 一個來自左端,另一個來自右端。當顧客通過左入口到達酒店時,他們被分配到最靠近左入口的空房間。類似地,當顧客通過右入口到達酒店時,他們被分配

POJ 2586-暴力

題目:考驗英語和語文能力。 借鑑於:不知道是誰寫的不太詳細的題目解析;詳細版我寫在後面了。 >錯誤分析:不想讀題。題目出的有點不夠清楚。 題目拆解: 1)12個月的盈虧分析 2)每一個月要麼是盈要麼是虧,不同月份盈利額不會改變;虧損額也不會改變。(照應INPU

白演算法練習 解析幾何 POJ 1375

Intervals Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4833 Accepted: 1462 Description In the ceiling in

POJ 1050 To the Max (最大連續區間和+暴力列舉,

Description Given a two-dimensional array of positive and negative integers, a sub-rectangle is any contiguous sub-array of size 1*1 or

POJ 2545+2591+2247+1338簡單

變形 humble long 列數 最簡 能夠 poj string num 【題意簡述】:就是有這種一個序列。就拿當p1 = 2,p2 = 3, p3 = 5,來舉例。由這三個數為基準組成的序列是: 2,3,4,5,6,8,9,10,12……如今給你這個序列數組的下標

4452 模擬

str dsm esp iostream ack mes har += trac #include<stdio.h> #include<string.h> #include<iostream> using namespace std;

51nod 1283 最周長(

com cin ide splay include 面積 nod lac eml 1283 最小周長 題目來源: Codility 基準時間限制:1 秒 空間限制:131072 KB 分值: 5 難度:1級算法題 收藏 關註 取消關註 一個矩形的面積為S,