记录一道学长们说有点难度的题目

好好玩啊这道题

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完虐的我的一天的更多相关文章

  1. poj-3279 poj-1753(二进制枚举)

    题目链接:http://poj.org/problem?id=3279 题目大意: 有一个m*n的棋盘(1 ≤ M ≤ 15; 1 ≤ N ≤ 15),每个格子有两面分别是0或1,每次可以对一个格子做 ...

  2. CUGBACM_Summer_Tranning1 二进制枚举+模拟+离散化

    整体感觉:这个组队赛收获还挺多的.自从期末考试以后已经有一个多月没有 做过组队赛了吧,可是这暑假第一次组队赛就找回了曾经的感觉.还挺不错的!继续努力!! 改进的地方:这次组队赛開始的时候题目比較难读懂 ...

  3. UVA 1151二进制枚举子集 + 最小生成树

    题意:平面上有n个点(1<=N<=1000),你的任务是让所有n个点连通,为此, 你可以新建一些边,费用等于两个端点的欧几里得距离的平方.另外还有q(0<=q<=8)个套餐(数 ...

  4. Good Bye 2015B(模拟或者二进制枚举)

    B. New Year and Old Property time limit per test 2 seconds memory limit per test 256 megabytes input ...

  5. Poj(2784),二进制枚举最小生成树

    题目链接:http://poj.org/problem?id=2784 Buy or Build Time Limit: 2000MS   Memory Limit: 65536K Total Sub ...

  6. POJ 2436 二进制枚举+位运算

    题意:给出n头牛的得病的种类情况,一共有m种病,要求找出最多有K种病的牛的数目: 思路:二进制枚举(得病处为1,否则为0,比如得了2 1两种病,代号就是011(十进制就是3)),首先枚举出1的个数等于 ...

  7. hdu 3118(二进制枚举)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3118 思路:题目要求是去掉最少的边使得图中不存在路径长度为奇数的环,这个问题等价于在图中去掉若干条边, ...

  8. HDU 5025Saving Tang Monk BFS + 二进制枚举状态

    3A的题目,第一次TLE,是因为一次BFS起点到终点状态太多爆掉了时间. 第二次WA,是因为没有枚举蛇的状态. 解体思路: 因为蛇的数目是小于5只的,那就首先枚举是否杀死每只蛇即可. 然后多次BFS, ...

  9. 南阳OJ-91-阶乘之和---二进制枚举(入门)

    题目链接:http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=91 题目大意: 给你一个非负数整数n,判断n是不是一些数(这些数不允许重复使用,且为 ...

随机推荐

  1. 汇编语言从入门到精通-5微机CPU的指令系统2

    微机CPU的指令系统 5.2.2 标志位操作指令 标志位操作指令是一组对标志位置位.复位.保存和恢复等操作的指令. 1.进位CF操作指令 a.清进位指令CLC(Clear Carry Flag):CF ...

  2. 吴裕雄--天生自然TensorFlow2教程:全连接层

    out = f(X@W + b) out = relut(X@W + b) import tensorflow as tf x = tf.random.normal([4, 784]) net = t ...

  3. 将一行很长的js代码格式化输出方便查看

    之前的一行js代码,有2万多字符,打开这个网址,粘贴到左边空白框,点下面格式化: 参考下面文章: 数千行的js代码变成了一行,如何复原,该换行的换行,该对齐的对齐_开发工具_小邯韩的博客-CSDN博客 ...

  4. Linux环境查看Java应用消耗资源情况

    linux线上资源耗时定位 https://www.cnblogs.com/wuchanming/p/7766994.html 1. jps -ml 查看服务器上运行的Java程序 2. jmap 查 ...

  5. nacos作为配置中心动态刷新@RefreshScope添加后取值为null的一个问题

    之前springboot项目常量类如下形式: @Component @RefreshScope//nacos配置中心时添加上 public class Constants { @Value(" ...

  6. SWD学习笔记

    SWD其实和JTAG类似,是一种调试串口. JTAG大致了解了一下.JTAG(Joint Test Action Group)主要4 lines:TMS(模式选择),TCK(时钟),TDI(数据输入) ...

  7. Java连载78-深入自动拆装箱、Date类和SimpleDateFormat格式化

    一.深入自动拆装箱 1.直接举例: public class D78_AutomaticUnpackingAndPacking{ public static void main(String[] ar ...

  8. Django 学习之Xadmin

    一.xadmin的特点 1.基于Bootstrap3:Xadmin使用Bootstrap3.0框架精心打造.基于Bootstrap3,Xadmin天生就支持在多种屏幕上无缝浏览,并完全支持Bootst ...

  9. Spring Schedule 实现定时任务

    很多时候我们都需要为系统建立一个定时任务来帮我们做一些事情,SpringBoot 已经帮我们实现好了一个,我们只需要直接使用即可,当然你也可以不用 SpringBoot 自带的定时任务,整合 Quar ...

  10. CSS - 去除图片img底侧空白缝隙

    1. 图片底部有空隙 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...