UVA 6480 Zombie Invasion(模拟退火)
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's Treasure Chest【暴力】
题意:和上次的cf的ZeptoLab的C一样,是紫书的例题7-11 不过在uva上交的时候,用%I64d交的话是wa,直接cout就好了 #include<iostream> #inclu ...
- 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 ...
- uva 12325 Zombie's Treasure Chest
https://vjudge.net/problem/UVA-12325 题意: 一个箱子,体积为N 两种宝物,体积为S1.S2,价值为V1.V2,数量无限 最多装多少价值的宝物 数据范围:2^32 ...
- UVA 12325 Zombie'sTreasureChest 宝箱 (分类枚举)
看上去非常像背包的问题,但是体积太大了. 线性规划的知识,枚举附近点就行了,优先选性价比高的, 宝物有两种体积为S0,价值V0,体积S1,价值V1. 枚举分以下几种: 1:枚举拿宝物1的数量,然后尽量 ...
- Uva 12325 Zombie's Treasure Chest (贪心,分类讨论)
题意: 你有一个体积为N的箱子和两种数量无限的宝物.宝物1的体积为S1,价值为V1:宝物2的体积为S2,价值为V2.输入均为32位带符号的整数.你的任务是最多能装多少价值的宝物? 分析: 分类枚举, ...
- UVA - 12325 Zombie'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 请求数据 error
解决办法如下: 0x1 ->请求数据时加上缺少的类型 AFHTTPSessionManager *manager = [selfAFHTTPSessionManager];// manag ...
- 使用Git上传代码到GitHub详细的不能再详细教程
据说不会用GitHub的程序员连菜鸟都不算,确实,GitHub上有大量优秀的代码,我们也可以将自己的代码分享上去. 首先,你要有一个GitHub的账号,https://github.com/在官网注册 ...
- gmake使用注意
今天使用gmake把sgml变成html的时候出现了无法找到gmake的困惑(本人linux为ubuntu15.04),上网搜索发现: gmake是GNU Make的缩写.Linux系统环境下的mak ...
- 断开/删除 SVN 链接(.svn)的几种方法
上传到正式的服务器时需要去掉这些不必要的文件,找到了几种方法: 1.windows下: xcopy project_dir project_dir_1 /s /i (从project_dir 复制文件 ...
- FreePascal的VMT与Delphi不一致,没有负方向
因为不需要与C++兼容嘛:http://www.freepascal.org/docs-html/prog/progsu168.html 如果要想取得它真正的VMT,可以Pointer强行转换+100 ...
- Solr4.7从数据库导数据
实际工程应用中,从数据库导出数据创建索引再常见不过了,现在实验一下从数据库导入数据创建索引. 一.版本说明 Solr版本:4.7.0 数据库:sqlserver2005 二.配置步骤 1. 准备的j ...
- linux c 得到时间
ctime: 将时间和日期以字符串格式表示头文件: time.h函数定义: char *ctime(const time_t *timep); 应用举例:#include <stdio.h> ...
- win32多线程程序设计笔记(第五章)
前面章节介绍了线程创建等过程,现在的问题是:如何在某个线程内终止另外一个正在运行的线程? windows核心编程中提到终止运行线程的方法: 1)线程函数自己返回: 2)线程通过调用ExitThread ...
- Java进阶03 IO基础
链接地址:http://www.cnblogs.com/vamei/archive/2013/04/11/3000905.html 作者:Vamei 出处:http://www.cnblogs.com ...
- C-KMP
一.BF算法 --传统算法 BF算法是普通的模式匹配算法,BF算法的思想就是将目标串S的第一个字符与模式串P的第一个字符进行匹配,若相等,则继续比较S的第二个字符和P的第二个字符:若不相等,则比较S的 ...