二进制枚举之被RE完虐的我的一天
记录一道学长们说有点难度的题目
好好玩啊这道题
ACM程序设计大赛是大学级别最高的脑力竞赛,素来被冠以"程序设计的奥林匹克"的尊称。大赛至今已有近40年的历史,是世界范围内历史最悠久、规模最大的程序设计竞赛。比赛形式是:从各大洲区域预赛出线的参赛队伍,于指定的时间、地点参加世界级的决赛,由1个教练、3个成员组成的小组应用一台计算机解决7到13个生活中的实际问题。
现在假设你正在参加ACM程序设计大赛,这场比赛有 n 个题目,对于第 i 个题目你有 a_i 的概率AC掉它,如果你不会呢,那么这时候队友的作用就体现出来啦,队友甲有 b_i 的概率AC掉它, 队友乙有 c_i 的概率AC掉它,那么现在教练想知道你们队伍做出 x 个题目的概率。
Input
输入一个正整数T(T<=100),表示有T组数据,对于每组数据首先输入一个 n (7<=n<=13),表示有 n 个题目,接下来输入三行,
第一行输入 n 个数a_i,第二行输入 n 个数b_i,第三行输入 n 个数c_i, 其中 a_i, b_i, c_i 的意义如题,最后输入一个 x 表示教练想要知道你们队伍做出的题目数(x>=0)。
Output
输出一行表示结果,保留4位小数
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int i,j;
double gl[4][15];
double ac[15][15];
double eror[15];
int main()
{
int zu;
while(scanf("%d",&zu)!=EOF)
{
while(zu>0)
{
int n;
scanf("%d",&n);
for(i=1;i<=3;i++)
{
for(j=1;j<=n;j++)
{
scanf("%lf",&gl[i][j]);
}
}
int x;
scanf("%d",&x);
ac[0][0]=1;
for(i=1;i<=n;i++)
{
eror[i]=(1-gl[1][i])*(1-gl[2][i])*(1-gl[3][i]);//这里是每道题错的概率
}
for(i=1;i<=n;i++)//这里i表示的是题数
{
for(j=0;j<=i;j++)//这里j表示的是ac数
{
if(j==0)
ac[i][j]=ac[i-1][j]*(eror[i]);//第一道错题总是要一直错的 =^=
else
ac[i][j]=ac[i-1][j-1]*(1-eror[i])+ac[i-1][j]*eror[i];//可能是错了也可能是对了,很有意思
}
}
if(x>n)
printf("0.0000\n");
else
printf("%.4f\n",ac[n][x]);
zu--;
}
}
//cout << "Hello world!" << endl;
return 0;
}
然后在记录一些不懂怎么解决这个RE时我错了好多遍的题
Give an odd number n, (1<=n<=10000001) Given you an array which have n numbers : a[1], a[2] a[3] ... a[n].They are positive num.
There are n/2 numbers which appear twice and only one number appears once.
Now you should tell me the number which appears only once.
Input
There are several test cases end with EOF.
The first line there is a integer n.
Then the 2nd line there are n integer a[1],a[2]..a[n].
Output
For each case, output the number which appears only once.(英文出题觉得有点搞笑
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int g,ans;
int main()
{
while(~scanf("%d",&g))
{
scanf("%d",&ans);
int x;
for(int i=;i<g-;i++)
{
scanf("%d",&x);
ans=ans^x;
}
printf("%d\n",ans);
/*这个故事告诉我们RE了就不要再弄大数组了
直接输入的时候就把它干掉= =
都是泪千行啊*/ }
//cout << "Hello world!" << endl;
return ;
}
这道题也要记录一下
上午做的思路是差不多的,电脑睡眠的时候忽然重启
丢失了之后再写就没有输出了//发现了,好乌龙的错误啊,要不我能多ac一道题= = 把循环中的j误写成了i;看来用太多循环的时候要避免i,j这两个长得相似的--
在选举问题中,总共有n个小团体,每个小团体拥有一定数量的选票数。如果其中m个小团体的票数和超过总票数的一半,则此组合为“获胜联盟”。n个团体可形成若干个获胜联盟。一个小团体要成为一个“关键加入者”的条件是:在其所在的获胜联盟中,如果缺少了这个小团体的加入,则此联盟不能成为获胜联盟。一个小团体的权利指数是指:一个小团体在所有获胜联盟中成为“关键加入者”的次数。请你计算每个小团体的权利指数。
Input
输入数据的第一行为一个正整数T,表示有T组测试数据。每一组测试数据的第一行为一个正整数n(0<n<=20)。第二行有n个正整数,分别表示1到n号小团体的票数。
Output
对每组测试数据,在同一个行按顺序输出1到n号小团体的权利指数。
这是学长的代码~=……=~
#include <bits/stdc++.h>
using namespace std;
int n,t,i,j,s,tmp,a[],ans[],flag[];
int main()
{
cin>>t;
while(t--)
{
cin>>n;
s=;
for(i=;i<n;i++)
{cin>>a[i];s=s+a[i];}
memset(ans,,sizeof(ans));
for(i=;i<(<<n);i++)
{
tmp=;
memset(flag,,sizeof(flag));
for(j=;j<n;j++)
{
if(i&(<<j))
{tmp=tmp+a[j];flag[j]=;}
}
if(tmp<=s/)
{
for(j=;j<n;j++)
{
if(tmp+a[j]>s/&&flag[j]==)
ans[j]++;
}
}
}
for(i=;i<=n-;i++)
printf("%d ",ans[i]);
printf("%d\n",ans[n-]);
}
return ;
}
我还要学好多东西呢,写得太垃圾了
#include <iostream>
#include<bits/stdc++.h>
using namespace std; struct hs
{
int qz;
int piao;
int flag;
};
struct hs man[];
int n,i,j,temp,sum;
int main()
{
int zu;
while(cin>>zu)
{
while(zu>)
{
sum=;
cin>>n;
for(i=;i<n;i++)
cin>>man[i].piao;
for(i=;i<n;i++)
{sum=sum+man[i].piao;
man[i].qz=;}
for(i=;i<(<<n);i++)
{
temp=;
for(j=;j<n;j++)
man[j].flag=;
for(j=;j<n;j++)
{
if(i&(<<j))
{temp+=man[j].piao;
man[j].flag++;} }
if(temp>sum/)
{
for(j=;j<n;j++)
{
if(man[j].flag!=&&temp-man[j].piao<=sum/)
man[j].qz++;
}
}
}
for(int ki=;ki<n-;ki++)
printf("%d ",man[ki].qz);
printf("%d\n",man[n-].qz);
zu--;
}
} //cout << "Hello world!" << endl;
return ;
}
这一题也RE了= =
我和RE不得不说有仇
贴个标准答案
This time,suddenly,teacher Li wants to find out who have missed interesting DP lesson to have fun.The students who are found out will get strictly punishment.Because,teacher Li wants all the students master the DP algorithm.
However,Li doesn't want to waste the class time to call over the names of students.So he let the students to write down their names in one paper.To his satisfaction,this time, only one student has not come.
He can get the name who has not come to class,but,it is troublesome,and,teacher always have many things to think about,so,teacher Li wants you, who is in the ACM team, to pick out the name.
Input
There are several test cases.The first line of each case have one positive integer N.N is the number of the students,and N will not greater than 500,000.
Then,following N lines,each line contains one name of students who have attended class.The N-1 lines are presented after N lines.These N-1 lines indicates the names of students who have come to class this time,one name in one line.
The length of student's name is not greater than 30.
Process to the end of file.
Output
For each test case, first print a line saying "Scenario #k", where k is the number of the test case.Then output the name of the student who have not come to class.One case per line.Print a blank line after each test case, even after the last one.
(英文出题弄得我漏掉好多细节
#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
long int n,i;
char name[],tmp[];
int main(){
int cas=;
while(~scanf("%ld",&n))
{ memset(name,,sizeof(name));
for(i=;i<=*n-;i++)
{
scanf("%s",tmp);
for(int j=;j<;j++)
name[j]=name[j]^tmp[j];
}
printf("Scenario #%d\n",cas++);
cout<<name<<endl<<endl;//这里特别注意,题中说每组输出之后要有一行blank,所以多输出一个换行:-)
}
return ;
}
好累好累
今天的份额解决了
把昨天的补上 ;^ ;
二进制枚举之被RE完虐的我的一天的更多相关文章
- poj-3279 poj-1753(二进制枚举)
题目链接:http://poj.org/problem?id=3279 题目大意: 有一个m*n的棋盘(1 ≤ M ≤ 15; 1 ≤ N ≤ 15),每个格子有两面分别是0或1,每次可以对一个格子做 ...
- CUGBACM_Summer_Tranning1 二进制枚举+模拟+离散化
整体感觉:这个组队赛收获还挺多的.自从期末考试以后已经有一个多月没有 做过组队赛了吧,可是这暑假第一次组队赛就找回了曾经的感觉.还挺不错的!继续努力!! 改进的地方:这次组队赛開始的时候题目比較难读懂 ...
- UVA 1151二进制枚举子集 + 最小生成树
题意:平面上有n个点(1<=N<=1000),你的任务是让所有n个点连通,为此, 你可以新建一些边,费用等于两个端点的欧几里得距离的平方.另外还有q(0<=q<=8)个套餐(数 ...
- Good Bye 2015B(模拟或者二进制枚举)
B. New Year and Old Property time limit per test 2 seconds memory limit per test 256 megabytes input ...
- Poj(2784),二进制枚举最小生成树
题目链接:http://poj.org/problem?id=2784 Buy or Build Time Limit: 2000MS Memory Limit: 65536K Total Sub ...
- POJ 2436 二进制枚举+位运算
题意:给出n头牛的得病的种类情况,一共有m种病,要求找出最多有K种病的牛的数目: 思路:二进制枚举(得病处为1,否则为0,比如得了2 1两种病,代号就是011(十进制就是3)),首先枚举出1的个数等于 ...
- hdu 3118(二进制枚举)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3118 思路:题目要求是去掉最少的边使得图中不存在路径长度为奇数的环,这个问题等价于在图中去掉若干条边, ...
- HDU 5025Saving Tang Monk BFS + 二进制枚举状态
3A的题目,第一次TLE,是因为一次BFS起点到终点状态太多爆掉了时间. 第二次WA,是因为没有枚举蛇的状态. 解体思路: 因为蛇的数目是小于5只的,那就首先枚举是否杀死每只蛇即可. 然后多次BFS, ...
- 南阳OJ-91-阶乘之和---二进制枚举(入门)
题目链接:http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=91 题目大意: 给你一个非负数整数n,判断n是不是一些数(这些数不允许重复使用,且为 ...
随机推荐
- VB.NET中Sub和Function的区别
function是函数,sub是子程序,都可以传递参数,但函数有返回值,子程序没有 function 可以用自身名字返回一个值,sub 需定义别的变量,用传址方式传回值. Sub 过程与Functio ...
- P1025数的划分
P1025数的划分 #include <iostream> using namespace std; int n,k; int cnt; void dfs(int s,int step,i ...
- 最大流dinic板子
题目: https://www.luogu.com.cn/problem/P3376 #include <bits/stdc++.h> using namespace std; ; con ...
- J.K.罗琳女士---《失败的好处和想象的重要性》
目录 sohu ruanyifeng web sohu http://www.sohu.com/a/166181502_467718 <哈利波特>的作者J.K.罗琳女士在出席一次哈佛大学的 ...
- Linux命令:iostat命令
Linux系统中的 iostat是I/O statistics(输入/输出统计)的缩写,iostat工具将对系统的磁盘操作活动进行监视.它的特点是汇报磁盘活动统计情况,同时也会汇报出CPU使用情况.同 ...
- 浅谈区块链和p2p网络
最近对区块链产生了兴趣就去了解了一下,分享一下.... 首先要先了解一下什么叫做区块链: 区块链:简单来说就是一种基于分布式数据存储.点对点传输.共识机制.加密算法等计算机技术的新型应用模式. 相信说 ...
- CS231n -Assignments 1 Q1 and Q2
前言 最近在youtube 上学习CS231n的课程,并尝试完成Assgnments,收获很多,这里记录下过程和结果以及过程中遇到的问题,我并不是只是完成需要补充的代码段,对于自己不熟悉的没用过的库函 ...
- Python 基础之字符串操作,函数及格式化format
一.字符串的相关操作 1.字符串的拼接 + strvar1 = "我爱你,"strvar2 = "亲爱的姑凉"res = strvar1 + strvar2pr ...
- 如何使用ffmpeg的c语言sdk实现对文件夹的操作
重要函数 打开文件夹:avio_open_dir() 读取文件夹:avio_read_dir() 关闭文件夹:avio_close_dir() 结构体, 操作目录的上下文:AVIODirContext ...
- C++11并发编程2------线程管理
本节内容: 启动一个线程 每个程序都至少会有一个线程,main函数是执行入口,我们称之为主线程,其余子线程有各自的入口函数,主线程和子线程同时运行.子线程在std::thread对象创建时启动. 1. ...