A group of survivors has arrived by helicopter to an isolated island. The island is made up of a long

narrow strip of villages. The infected survivors arrived in the village to the far east and accidentally

infected the native population. The islanders are now attempting to escape the zombies that have

appeared on the east coast.

You are given N cases with 20 non-negative integers that represent the number of islanders at a

given village. The villages are represented from west to east (left to right, respectively), with the

zombies moving in from the east. The islanders have peculiar customs for traveling and will only move

between villages in pairs. Curiously, for every pair that travels between two villages, only one of them

ever survives the trip. As the zombies move west, islanders will travel to the village immediately west

of their current village as long as there are at least two islanders there. If there are an odd number

people in a village then one stays in the village and the rest move to the next village in pairs. Once

the islanders reach the village on the west coast, they will stop traveling.

Determine how many islanders remain at each village and the number that make it safely to the

village on the west coast (far left).

Input

The first line of data represents the number of data sets you will read in, N (1 ≤ N ≤ 50).

There will then be N lines of twenty 20 non-negative integers each. Each integer (≤ 1000) represents

the number of islanders who reside in a village. The leftmost integer represents the village on the west

coast, and the rightmost integer represents the village on the east coast.

Output

Your output will be N lines of twenty 20 non-negative integers. The left most number will represent

the number of islanders that reached the west. Each number to the right will represent the number of

people that stayed behind in each village.

Sample Input

1

0 0 0 0 77 0 0 99 0 0 0 40 0 0 0 17 0 1 13 10

Sample Output

5 1 0 0 1 1 0 1 1 0 0 1 0 0 1 1 1 0 0 0

模拟的水题。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<limits.h>
typedef long long LL;
using namespace std;
int num[25];
int main()
{
int t;
cin>>t;
while(t--)
{
for(int i=1;i<=20;i++)
scanf("%d",&num[i]);
int sum=0,temp;
for(int i=20;i>=1;i--)
{
temp=num[i]+sum;
sum=temp/2;
if(temp%2)
num[i]=1;
else
num[i]=0;
}
cout<<temp;
for(int i=2;i<=20;i++)
cout<<" "<<num[i];
cout<<endl;
}
return 0;
}

UVA 6480 Zombie Invasion(模拟退火)的更多相关文章

  1. UVa 12325 Zombie's Treasure Chest【暴力】

    题意:和上次的cf的ZeptoLab的C一样,是紫书的例题7-11 不过在uva上交的时候,用%I64d交的话是wa,直接cout就好了 #include<iostream> #inclu ...

  2. UVa 12325 - Zombie's Treasure Chest-[分类枚举]

    12325 Zombie’s Treasure Chest Some brave warriors come to a lost village. They are very lucky and fi ...

  3. uva 12325 Zombie's Treasure Chest

    https://vjudge.net/problem/UVA-12325 题意: 一个箱子,体积为N 两种宝物,体积为S1.S2,价值为V1.V2,数量无限 最多装多少价值的宝物 数据范围:2^32 ...

  4. UVA 12325 Zombie'sTreasureChest 宝箱 (分类枚举)

    看上去非常像背包的问题,但是体积太大了. 线性规划的知识,枚举附近点就行了,优先选性价比高的, 宝物有两种体积为S0,价值V0,体积S1,价值V1. 枚举分以下几种: 1:枚举拿宝物1的数量,然后尽量 ...

  5. Uva 12325 Zombie's Treasure Chest (贪心,分类讨论)

    题意: 你有一个体积为N的箱子和两种数量无限的宝物.宝物1的体积为S1,价值为V1:宝物2的体积为S2,价值为V2.输入均为32位带符号的整数.你的任务是最多能装多少价值的宝物? 分析: 分类枚举, ...

  6. UVA - 12325 Zombie's Treasure Chest (分类搜索)

    题目: 有一个体积为N的箱子和两种数量无限的宝物.宝物1的体积为S1,价值为V1:宝物2的体积为S2,价值为V2.输入均为32位带符号整数.计算最多能装多大价值的宝物,每种宝物都必须拿非负整数个. 思 ...

  7. Instruments Tutorial for iOS: How To Debug Memory Leaks【转】

    If you're new here, you may want to subscribe to my RSS feed or follow me on Twitter. Thanks for vis ...

  8. Instruments Tutorial for iOS: How To Debug Memory Leaks

    http://www.raywenderlich.com/2696/instruments-tutorial-for-ios-how-to-debug-memory-leaks Update 4/12 ...

  9. uva 10228 - Star not a Tree?(模拟退火)

    题目链接:uva 10228 - Star not a Tree? 题目大意:给定若干个点,求费马点(距离全部点的距离和最小的点) 解题思路:模拟退火算法,每次向周围尝试性的移动步长,假设发现更长处, ...

随机推荐

  1. diff两个文件夹里的东西

    diff --help -x, --exclude=PAT               exclude files that match PAT 排除某个类型的文件 -u, -U NUM, --uni ...

  2. 将 Excel 数据导入 MySql

    能承受上万数据量,速度快,并且使用了事务,不会出现某条数据错误而导致部分数据插入(要是全部成功要是一条都不成功,测试过程中没出现失败),需要的朋友可以参考下 1.NPOI 2.MySql.Data 这 ...

  3. POJ2069 最小球体覆盖, 模拟退火

    只是套了个模板,模拟退火具体的过程真心不懂阿 //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #in ...

  4. Codeforces 331A2 - Oh Sweet Beaverette (70 points)

    贪心搞就行,用map记录每个数出现的下标,每次都取首尾两个.将中间权值为负的删掉后取sum值最大的就行. #include<iostream> #include<algorithm& ...

  5. Servlet 实现文件的上传与下载

    这段时间尝试写了一个小web项目,其中涉及到文件上传与下载,虽然网上有很多成熟的框架供使用,但为了学习我还是选择了自己编写相关的代码.当中遇到了很多问题,所以在此这分享完整的上传与下载代码供大家借鉴. ...

  6. Excel VBA ——批量工作表重命名

    虽然平常在用excel 2010重命名工作表的时候,一般可能会用"双击工作表"的方法来重名,但是遇到大批量重名的时候就很麻烦. 我的方法,先建一张新表,然后在第一列写好要命名的表名 ...

  7. BZOJ 1578: [Usaco2009 Feb]Stock Market 股票市场( 背包dp )

    我们假设每天买完第二天就卖掉( 不卖出也可以看作是卖出后再买入 ), 这样就是变成了一个完全背包问题了, 股票价格为体积, 第二天的股票价格 - 今天股票价格为价值.... 然后就一天一天dp... ...

  8. 演练2-4:CodeFirst实例之“电影网站制作”

    原文出处:http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/adding-a-model EntityFr ...

  9. cocos2d-x游戏开发系列教程-坦克大战游戏之敌方坦克AI的编写

    在上篇我们完成了子弹和地图碰撞的检测,在这篇我们将完成敌方坦克AI的编写. 具体思路是屏幕中保持有四个敌方坦克,然后坦克随机方向运动,并且子弹消失后1秒发射一次 1.我们新建一个敌方坦克的AI类来控制 ...

  10. Mac下显示隐藏文件 以及修改 hosts文件内容

    修改hosts 文件内容: 进入etc 文件夹,找到hosts 文件,把该文件复制出来,修改完里面的内容后,先把etc中的hosts 文件删除,然后在把修改后的文件脱机去 可能需要管理员的密码,你输入 ...