题目HDU 2103:http://acm.hdu.edu.cn/showproblem.php?pid=2103

Problem Description

As far as we known,there are so many people in this world,expecially in china.But many people like LJ always insist on that more people more power.And he often says he will burn as much babies as he could.Unfortunatly,the president XiaoHu already found LJ's extreme mind,so he have to publish a policy to control the population from keep on growing.According the fact that there are much more men than women,and some parents are rich and well educated,so the president XiaoHu made a family planning policy:
According to every parents conditions to establish a number M which means that parents can born M children at most.But once borned a boy them can't born other babies any more.If anyone break the policy will punished for 10000RMB for the first time ,and twice for the next time.For example,if LJ only allowed to born 3 babies at most,but his first baby is a boy ,but he keep on borning another 3 babies, so he will be punished for 70000RMB(10000+20000+40000) totaly.

Input

The first line of the input contains an integer T(1 <= T <= 100) which means the number of test cases.In every case first input two integers M(0<=M<=30) and N(0<=N<=30),N represent the number of babies a couple borned,then in the follow line are N binary numbers,0 represent girl,and 1 represent boy.

Output

For each test case you should output the total money a couple have to pay for their babies.

解题思路

感觉这道题非常非常的坑,明明程序都已经能正常跑出程序了,却一直不能AC……看了看网络上有和我一样一直WA的人,估计他也一头雾水。后来看论坛才知道要将int改为long long型才能通过,虽然是在不理解这样是为什么,先放出修改前的代码,以后想通了再进行修改。这里直接放出代码:

#include<iostream>
#include<cstdio>
using namespace std; int main()
{
int a[50];
int i,j,m,n;
scanf("%d",&i);
while(i--)
{
long long num=0,rmb=0;
int t=1;
scanf("%d %d",&m,&n);
for(j=0;j<n;j++)
scanf("%d",&a[j]);
for(j=0;j<n;j++)
{if((num==1)||(j>m-1)) /*超出预定数目,或者生了男孩*/
{
rmb=rmb+1000*t;
t=t*2;
}
if(a[j]==1) num=1;
}
printf("%I64d RMB\n",rmb);
}
return 0;
}

更新:

在做ACM题时,经常都会遇到一些比较大的整数。而常用的内置整数类型常常显得太小了:其中long 和 int 范围是[-231,231),即-21474836482147483647。而unsigned范围是[0,2^32),即04294967295。也就是说,常规的32位整数只能够处理40亿以下的数。

那遇到比40亿要大的数怎么办呢?这时就要用到C++的64位扩展了。不同的编译器对64位整数的扩展有所不同。

最新文章

  1. java 设计模式
  2. Ionic2学习笔记(8):Local Storage& SQLite
  3. CCNA 6.9
  4. oracle 物化视图及创建索引
  5. 使用 Windows PowerShell 管理Windows Azure映像
  6. 无法将类型“System.Collections.Generic.IEnumerable&lt;EmailSystem.Model.TemplateInfo&gt;”隐式转换为“System.Collections.Generic.List&lt;EmailSystem.Model.TemplateInf
  7. JAVA冒泡排序/JAVA冒泡排序再找出给定数据中的最大值最小值/JAVA数组排序
  8. 兼容性之IOS下label 无法点击
  9. @page指令 validateRequest的作用
  10. SQL Server 使用ROW_NUMBER()进行分页
  11. .NET编程规范
  12. 笔记整理——linux程序设计
  13. canvas动态小球重叠效果
  14. Roundcube Webmail File Disclosure Vulnerability(CVE-2017-16651)
  15. 转:Git Submodule管理项目子模块
  16. @Param注解
  17. BZOJ3569 DZY Loves Chinese II(随机化+树上差分+线性基)
  18. spring-data-jpa初步认识
  19. centos7 使用rsync 实现文件同步
  20. cocos2d-x -Lua 字符串

热门文章

  1. 使用MDI窗体实现多窗口效果
  2. CF 360 E Levko and Game —— 贪心+最短路
  3. win32 获取 HotKey 控件中的内容(HKM_GETHOTKEY)
  4. DSP/BIOS程序启动顺序
  5. 解析CmdLine参数
  6. STL string大小写 转换
  7. sql server 表索引碎片处理
  8. k8s组件简介
  9. 关于web中注册倒数的问题(亲测)
  10. Maven的pom实例