奇怪的比赛
来源:互联网 发布:淘宝品牌授权资质 编辑:程序博客网 时间:2024/04/28 21:13
#include<iostream>#include<cstdio>#include<string.h>#include<string>#include<cstring>#include<algorithm>using namespace std;const int target = 100;int globalcnt = 0;int cnt[11];int Next(int id,int cur); //开始答第id道题int main(){ int init = 10; //起始分数 memset(cnt,0,sizeof(cnt)); Next(1,init); cout << "total solution is " << globalcnt << endl; return 0;}int Next(int id,int cur){ int current = cur; if(id > 10) //已经答完10道题 { if(cur == target) { cout << "success" << endl; ++globalcnt; for(int i = 1; i < 11; ++i) { //cout << i << endl; printf("%d",cnt[i]); } cout << endl; return 1; } return 0; } cnt[id] = 1; Next(id+1,cur << 1); //答对此题,分数倍增 cnt[id] = 0; Next(id+1,cur-id); return 0;}
问题描述:
某电视台举办了低碳生活大奖赛。题目的计分规则相当奇怪:
每位选手需要回答10个问题(其编号为1到10),越后面越有难度。答对的,当前分数翻倍;答错了则扣掉与题号相同的分数(选手必须回答问题,不回答按错误处理)。
每位选手都有一个起步的分数为10分。
某获胜选手最终得分刚好是100分,如果不让你看比赛过程,你能推断出他(她)哪个题目答对了,哪个题目答错了吗?
如果把答对的记为1,答错的记为0,则10个题目的回答情况可以用仅含有1和0的串来表示。例如:0010110011 就是可能的情况。
你的任务是算出所有可能情况。每个答案占一行。
错误代码:
#include<iostream>#include<cstdio>#include<string.h>#include<string>#include<cstring>#include<algorithm>using namespace std;const int target = 100;int globalcnt = 0;int cnt[11];int Next(int id,int cur); //开始答第id道题int main(){ int init = 10; //起始分数 memset(cnt,0,sizeof(cnt)); Next(1,init); return 0;}int Next(int id,int cur){ int current = cur; if(cur == target) { cout << "success" << endl; ++globalcnt; for(int i = 1; i < 11; ++i) { //cout << i << endl; printf("%d",cnt[i]); } cout << endl; return 1; } if(id == 10) //已经答完10道题 { //cout<<"fail" <<endl; return 0; } cnt[id] = 1; Next(id+1,cur << 1); //答对此题,分数倍增 cnt[id] = 0; Next(id+1,cur-id); return 0;}
错误原因:
达到target即输出结果,但对于达到target后面的题目而言,每道题不是倍增当前分数就是减去题目Id,所以不能保证答完所有题后分数仍为target~
0 0
- 蓝桥杯&&奇怪的比赛
- 奇怪的比赛
- 4.奇怪的比赛
- 奇怪的比赛
- 奇怪的比赛
- 奇怪的比赛
- 奇怪的比赛--蓝桥杯
- 蓝桥杯-奇怪的比赛
- 奇怪的比赛 蓝桥杯
- 奇怪的比赛
- 奇怪的比赛--蓝桥杯
- 奇怪的比赛
- 奇怪的比赛
- LQ_奇怪的比赛
- 奇怪的比赛
- 奇怪的比赛
- 奇怪的比赛
- 奇怪的比赛
- poj 1502:MPI Maelstrom
- HDU 2006 求奇数的乘积
- 继承
- 【排序】Sort Colors
- 修改表字段
- 奇怪的比赛
- HDU 1676 Full Tank? 限制最短路(difficult)
- 怎样修改SWF中的链接?
- oracle timestamp 时间戳增加一天
- 地铁换乘(华为机试样题)
- C#的装箱与拆箱
- 34.打印十字图
- JMS
- 第三周作业