codechef The Army
来源:互联网 发布:codeblocks 知乎 编辑:程序博客网 时间:2024/05/18 22:17
Problem Description
N Soldiers are lined up for a memory test. They are numbered from 0 to N-1 from left to right.
In the test, there are M rounds. In each round, Captain selects one position. Soldier at that position will be numbered 0. All the soldiers to the right of selected position will be numbered one greater than the soldier to his left. All the soldiers to the left of selected position will be numbered one greater than the soldier to his right.
eg. if N = 6 and selected position is 3, then the numbering will be [3, 2, 1, 0, 1, 2].
After M rounds, Captain asked each soldier to shout out the greatest number he was assigned during the M rounds. In order to check the correctness, Captain asked you to produce the correct values for each soldier (That is the correct value each soldier should shout out).
Input
The first line of the input contains an integer T denoting the number of test cases.First line of each test case contains two integers, N and M.
Second line of each test case contains M integers, the positions selected by Captain, in that order.
Output
For each test case, output one line with N space separated integers.Constraints
1 ≤ T ≤ 10^41 ≤ N ≤ 10^5
1 ≤ M ≤ 10^5
1 ≤ Sum of N over all testcases ≤ 10^5
1 ≤ Sum of M over all testcases ≤ 10^5
0 ≤ Positions selected by captain ≤ N-1
Example
Input
24 1
1
6 2
2 3
Output
1 0 1 23 2 1 1 2 3
题解
模拟即可。
#include<cstdio>#include<cstring>#include<cstdlib>#include<iostream>#include<cmath>#include<algorithm>#define inf 1<<30#define eps -1using namespace std;int T,n,m,minw,maxw;void init(){scanf("%d%d",&n,&m);maxw=eps; minw=inf;int i,x;for(i=1;i<=m;i++) {scanf("%d",&x); maxw=max(maxw,x); minw=min(minw,x); }}void find(){int i;for(i=0;i<n;i++) {if(i<minw) printf("%d",maxw-i); else if(i>maxw) printf("%d",i-minw); else printf("%d",max(abs(maxw-i),abs(minw-i))); if(i<n-1) printf(" "); else printf("\n"); }}int main(){scanf("%d",&T);while(T--) {init(); find();}return 0;}
- codechef The Army
- In the army now
- In the Army Now
- Codechef Reach The Point
- (codechef)The Next Palindrome
- CODECHEF Fill The Matrix
- CF587C Duff in the Army
- codeforces587C Duff in the Army
- Ural1090-In the Army Now
- codechef The Lead Game 题解
- codechef The Morning Commute 题解
- codechef Closing the Tweets 题解
- 【CodeChef】Holes in the text
- 【Codechef】Tiptoe through the tulips
- 【CodeChef】 Queries on the String
- CodeChef Protecting The Poison【贪心】
- CodeChef PROTEPOI Protecting The Poison
- Army
- 自定义view中xml属性 提示Attribute "XXX" has already been defined
- ls/cd/pwd/whoami/mkdir/rmdir/rm/pos/top/touch/ln/mv/clear/tar (linux)!!!
- 关于Block的copy和循环引用的问题
- 第九周项目五(三)
- 模板-后缀数组
- codechef The Army
- 单引号,双引号,三引号的区别
- Hduoj1194 【水题】
- TabHost 之实现底部
- 第9周项目6-穷举法解决组合问题之年龄几何
- SDUT 1265-马拦过河卒(DFS)
- 第9周项目6(1)-百钱百鸡问题
- 使用vb脚本让电脑自动加入域源码
- final关键字之final变量