C小加

厚德 博学 求真 至善 The bright moon and breeze
posts - 145, comments - 195, trackbacks - 0, articles - 0
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

NYOJ 428 悖论问题 解题报告

Posted on 2011-11-10 17:23 C小加 阅读(1222) 评论(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;
}

Feedback

# re: NYOJ 428 悖论问题 解题报告  回复  更多评论   

2011-11-15 23:49 by 游客
电子资源分享【第二期】
在线热点论坛,各种学习资源等着你,上千本精品电子书学习资料,多年收藏,陆续上传中,也欢迎你来分享各类资料。
电子书
鸟哥的私房菜基础学习篇(第二版)
http://www.olhot.net/forum.php?mod=viewthread&tid=241&fromuid=9
Linux网络编程
http://www.olhot.net/forum.php?mod=viewthread&tid=240&fromuid=9
UNIX环境高级编程第二版
http://www.olhot.net/forum.php?mod=viewthread&tid=78&fromuid=9
C#编程深度探索
http://www.olhot.net/forum.php?mod=viewthread&tid=65&fromuid=9
TCP/IP详解 卷1:协议
http://www.olhot.net/forum.php?mod=viewthread&tid=3&fromuid=9
TCP/IP详解(卷2):实现
http://www.olhot.net/forum.php?mod=viewthread&tid=4&fromuid=9
TCP/IP详解 卷3:TCP事务协议、HTTP、NNTP和UNIX域协议
http://www.olhot.net/forum.php?mod=viewthread&tid=5&fromuid=9
...
项目源代码
VC++开发的四国军棋网络游戏源码
http://www.olhot.net/forum.php?mod=viewthread&tid=89&fromuid=9
...
美图赏析
可爱精致小脸美女林晓
http://www.olhot.net/forum.php?mod=viewthread&tid=298&fromuid=9
黄昏の邂逅
http://www.olhot.net/forum.php?mod=viewthread&tid=297&fromuid=9

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理