A group of connected vors has arrived by helicopter to an isolated island. The island is made up of a long
Narrow strip of different ages. The infected specified vors 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
Given village. The ages are represented from west to east (left to right, respectively), with
Zombies moving in from the east. The Islanders have peculiar customs for traveling and will only move
Between versions ages in pairs. Curiously, for every pair that travels between two versions ages, only one of them
Ever ves 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 does islanders remain at each village and the number that make it safely to
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
People that stayed behind in each village.
Sample Input
1
0 0 0 0 77 0 99 0 0 0 40 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 0 0 0
Simulated question.
#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;}
Va 6480 zombie invasion (Simulated Annealing)