Posted on 2011-11-10 17:23
C小加 閱讀(1236)
評論(1) 編輯 收藏 引用 所屬分類:
解題報告
NYOJ地址:
http://acm.nyist.net/JudgeOnline/problem.php?pid=428題意都理解了好久好久,最后問了張云聰才知道題意,原來悖論是這樣想滴。
我用樣例解釋一下題意:
第一組數據:很明顯題上沒有正確答案,所以概率是0,可是選項里邊有0,你又不能選,所以產生悖論。
第二組數據:也沒有正確答案,概率是0,選項里沒有0,所以不會產生悖論。
第三組數據:選1/2對,選1/3也對,所以概率是5/6。選項里沒有5/6,所以選擇正確答案的概率是0,又因為有0這個選項,結果產生悖論。
理解題意之后,代碼就很容易實現了,我想著用字符串處理會簡單點,因為我要用map容器。不過結果要比想象中復雜的多,后來改用整型試了下,比想象中簡單多了。
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <map>
#include <cmath>
using namespace std;
map<int,int> m;
map<int,int>::iterator iter;
int n;
void Init()
{
m.clear();
}
void Read()
{
string str;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
int a,b;
scanf("%d/%d",&a,&b);
if(n%b) continue;
m[n/b*a]++;
}
}
bool Solve()
{
int sum=0;
for(iter=m.begin();iter!=m.end();iter++)
{
if(iter->first==iter->second)
{
sum+=iter->first;
}
}
if(sum==m[sum])
return false;
else if(m[0]==0)
return false;
else
return true;
}
int main()
{
//freopen("input","r",stdin);
int t;
cin>>t;
while(t--)
{
Init();
Read();
if(Solve())
{
printf("Yes\n");
}
else printf("No\n");
}
return 0;
}