首页 > 代码库 > UVA 6480 Zombie Invasion(模拟退火)
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
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(模拟退火)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。