hdu 6560 思维

The Hermit

Time Limit: 25000/15000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 103 Accepted Submission(s): 69

Problem Description
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. He has chosen this path of self-discovery and, as a result, has reached a heighted state of awareness

dhh loves to listen to radio. There are N 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 meansi 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 k and i 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.

Input
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

Output
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.

Sample Input
2
7
1 2 3 4 3 2 1
10
1 1 2 3 4 4 3 2 2 1

Sample Output
Case 1: 2
Case 2: 0
Hint

In the first testcase of the example, the number of stations that can receive the perfect signal from each station i i 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

题意:

在一条直线上有N个基站,坐标是从1~N。他们每个基站都有一个信号辐射范围,是[i-radi+1,i+radi-1]。每个基站信号覆盖的最左端是非递减的。对于每个基站都有(不一定有)一些基站是能接受到完美信号的基站。要求满足下面的条件。
对于基站k来说:

  1. k<i
  2. 存在另一个j,j满足k<=j<i,并且dis(k,j)>=dis(j,i)
  3. 基站j的信号能够覆盖到k和i

思路:

因为那个最左端非递减的性质,以及坐标是从1~N这两点。可以推出满足这些的点的数据只能是:

  1. 1 2 3 4 5 6 7 8 递增不超过1的
  2. 2 2 2 2 2 2 2 2 都相同的
  3. 10 8 5 3 2 1 这样递减的
  4. 三者混合起来的

分别对于前三个讨论,都能发现除了i基站和i基站前面一个基站不能接受到完美信号,剩下的它能覆盖到的都能接受到完美信号。

代码:

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t,n,x,cas=1;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        int ans=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&x);
            if(i>2&&x>2)
                ans^=(x-2);
        }
        printf("Case %d: %d\n",cas++,ans);
    }
    return 0;
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值