日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

THE HERMIT

發布時間:2024/3/26 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 THE HERMIT 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目描述
The Hermit stands alone on the top of a mountain with a lantern in his hand. The snow-capped mountain range symbolises the Hermit’s spiritual achievement, growth and accomplishment.
Hehas chosen this path of self-discovery and, asa result, has reached a heighted state of awareness.

dhh loves to listen to radio. There are radio stations on a number axis, and the i-th station is located at xi=i. The broadcasting scope of the i-th station is radi, which means stations in the interval [i - radi + 1,i + radi - 1] can receive the signal from the i-th station. For some unknown reason, the left boundary that can receive the i-th station’s signal is non-descending, which means i - radi + 1≤ i + 1 - radi+1 + 1.
Now dhh wants to listen to the radio from station i, and he finds that the station k, satisfying both of the following conditions, can receive perfect signal from the station i:
·k < i and station k can receive station i’s signal.
·There exists another station j(k≤j<i) such that station and can both receive the signal from station j and the distance between station k and j is greater than or equal to the distance between station j and i.
Now dhh wonders for each station i, how many stations can receive the perfect signal from station i.

輸入
The first line of the input contains one integer T≤20, denoting the number of testcases. Then T testcases follow. For each testcase:
·The first line contains one positve integer N.
·The second line contains N positive integers rad1, rad2 ,…, radN.
It’s guaranteed that 1≤N≤106 , i-radi+1≥1 and i + radi-1≤N

輸出
For the k-th testcase, output “Case k: ans” in one line, where ans represents the xor result of answer for each radio station i.
xor is a bitwise operation, which takes two bit patterns of equal length and performs the logical exclusive OR operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. In this we perform the comparison of two bits, being 1 if the two bits are different, and 0 if they are the same.

樣例輸入
2
7
1 2 3 4 3 2 1
10
1 1 2 3 4 4 3 2 2 1

樣例輸出
Case 1: 2
Case 2: 0

提示
In the first testcase of t he example, t he number of stations that can receive t he perfect signal from each station i is respectively 0, 0, 1, 2, 1, 0, 0 in order, so the answer must be
0 xor 0 xor 1 xor 2 xor 1 xor 0 xor 0 = 2

思路
因為每個基站的輻射的左邊界是非下降的,因此每個基站能接受到其信號的基站數是該基站的輻射范圍減去兩邊邊界與該基站位置減去兩邊邊界的最小值

代碼實現

#include<cstdio> #include<algorithm> using namespace std;int main() {int T;scanf("%d",&T);for(int id=1;id<=T;id++){int n;int ans=0;scanf("%d",&n);for(int i=1;i<=n;i++){int temp;scanf("%d",&temp);temp=max(0,min(i-2,temp-2));ans^=temp;}printf("Case %d: %d\n",id,ans);}return 0; }

總結

以上是生活随笔為你收集整理的THE HERMIT的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。