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(模拟退火)的更多相关文章
-
UVa 12325 Zombie&#39;s Treasure Chest【暴力】
题意:和上次的cf的ZeptoLab的C一样,是紫书的例题7-11 不过在uva上交的时候,用%I64d交的话是wa,直接cout就好了 #include<iostream> #inclu ...
-
UVa 12325 - Zombie&#39;s Treasure Chest-[分类枚举]
12325 Zombie’s Treasure Chest Some brave warriors come to a lost village. They are very lucky and fi ...
-
uva 12325 Zombie&#39;s Treasure Chest
https://vjudge.net/problem/UVA-12325 题意: 一个箱子,体积为N 两种宝物,体积为S1.S2,价值为V1.V2,数量无限 最多装多少价值的宝物 数据范围:2^32 ...
-
UVA 12325 Zombie&#39;sTreasureChest 宝箱 (分类枚举)
看上去非常像背包的问题,但是体积太大了. 线性规划的知识,枚举附近点就行了,优先选性价比高的, 宝物有两种体积为S0,价值V0,体积S1,价值V1. 枚举分以下几种: 1:枚举拿宝物1的数量,然后尽量 ...
-
Uva 12325 Zombie&#39;s Treasure Chest (贪心,分类讨论)
题意: 你有一个体积为N的箱子和两种数量无限的宝物.宝物1的体积为S1,价值为V1:宝物2的体积为S2,价值为V2.输入均为32位带符号的整数.你的任务是最多能装多少价值的宝物? 分析: 分类枚举, ...
-
UVA - 12325 Zombie&#39;s Treasure Chest (分类搜索)
题目: 有一个体积为N的箱子和两种数量无限的宝物.宝物1的体积为S1,价值为V1:宝物2的体积为S2,价值为V2.输入均为32位带符号整数.计算最多能装多大价值的宝物,每种宝物都必须拿非负整数个. 思 ...
-
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 ...
-
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 ...
-
uva 10228 - Star not a Tree?(模拟退火)
题目链接:uva 10228 - Star not a Tree? 题目大意:给定若干个点,求费马点(距离全部点的距离和最小的点) 解题思路:模拟退火算法,每次向周围尝试性的移动步长,假设发现更长处, ...
随机推荐
-
我的微信小程序入门踩坑之旅
前言 更好的阅读体验请:我的微信小程序入门踩坑之旅 小程序出来也有一段日子了,刚出来时也留意了一下.不过赶上生病,加上公司里也有别的事,主要是自己犯懒,就一直没做.这星期一,赶紧趁着这股热乎劲,也不是 ...
-
iOS - SQLite 数据库存储
1.SQLite 数据库 SQLite 是一种轻型的嵌入式数据库,安卓和 iOS 开发使用的都是 SQLite 数据库.它占用资源非常低,在嵌入式设备中,可能需要几百 K 的内存数据就够了.他的处理速 ...
-
MongoDB (十一) MongoDB 排序文档
sort() 方法 要在 MongoDB 中的文档进行排序,需要使用sort()方法. sort() 方法接受一个文档,其中包含的字段列表连同他们的排序顺序.要指定排序顺序1和-1. 1用于升序排列, ...
-
select count的优化
select count的优化 2011-08-02 12:01:36 分类: Oracle 一般情况下,select count语句很难避免走全表扫描,对于上百万行的表这个语句使用起来就比较吃力了, ...
-
一个月AS2.0总结。
来这家公司一个月了,从最初学习它的木块,到流程,到组件,到改动,到自己做. 感觉好快. 1.AS2.0确实比較3.0差距太大.假设不是公司必须使用2.0,我是真不想使用. 2.代码重用性差.相同的代码 ...
-
自定义不等高的cell-(storyboard)
对比自定义等高cell,需要几个额外的步骤(iOS8开始才支持) 添加子控件和contentView之间的间距约束 设置tableViewCell的真实行高和估算行高 // 告诉tableView所有 ...
-
老代码多=过度耦合=if else?阿里巴巴工程师这样捋直老代码
简介 在业务开发的过程中,往往存在平台代码和业务代码耦合严重难以分离.业务和业务之间代码交织缺少拆解的现象.平台和业务代码交织导致不易修改,不同业务的代码交织增加了不同负责团队之间的协同成本.因此不论 ...
-
自学Zabbix之路15.1 Zabbix数据库表结构简单解析-Hosts表、Hosts_groups表、Interface表
点击返回:自学Zabbix之路 点击返回:自学Zabbix4.0之路 点击返回:自学zabbix集锦 自学Zabbix之路15.1 Zabbix数据库表结构简单解析-Hosts表.Hosts_grou ...
-
Windows 64位系统安装Apache2.4
Windows 64位系统安装Apache2.4 来自:百度经验:jingyan.baidu.com 现在大部分一键安装包多是32位的,并不支持64位,直接在64位的系统上使用会报错的,所以我这里就来 ...
-
Eletron 打开文件夹,截图
1.shell.openItem(fullPath) var fullpath = path.join(processPath)+Math.random()+".png"; she ...