NOJ [1173] Birdlike Angry Pig
来源:互联网 发布:风险矩阵法判断准则 编辑:程序博客网 时间:2024/06/12 19:59
- 问题描述
- There's no end to revenge.
Pigs like to eat birds' eggs, so birds decide to revenge.
For this, pigs decide to revenge as well.
Pigs give a task to a birdlike pig. They let he sneak into the birds group so that they can destroy the birds group.
Every bird has a ID number (It may not be unique). To let pigs know, the birdlike pig makes the "AND operation" amount all the birds' ID number and sign himself to the answer.For example:Birds are signed as 5, 3, 4. So the birdlike pig signs himself as (5 & 3 & 4 = 0).
One day, a group birds pass by pigs' home. So the angry pig want to know whether the birdlike pig is in. - 输入
- This problem has several cases. The first line of each case is an integer N (2 <= N <= 100 000).
Then follows a line with N integers, indicates the ID of each bird/birdlike pig. - 输出
- For each case, if you can find the birdlike pig then output the ID of birdlike pig. Or output 'CAUTION: NO BIRDLIKE'.构造一个数Ai=bird[1]&bird[2]&.....&bird[i-1]&bird[i+1]&......bird[n],与乘积分析类似,将Ai分为2部分,分别用数组C,D表示则C[i]=C[i-1]&bird[i],D[i]=D[i+1]&bird[i+1]
#include<stdio.h>
#include<string.h>
int bird[100010];
int first[100010];
int last[100010];
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=1;i<=n;i++)
{
scanf("%d",&bird[i]);
if(i==1)
first[1]=bird[1];
else
first[i]=first[i-1]&bird[i];
}
for(int i=n;i>=1;i--)
if(i==n)
last[n]=bird[n];
else
last[i]=(last[i+1]&bird[i]);
bool p=false;
for(int i=2;i<=n-1;i++)
{
if((first[i-1]&last[i+1])==bird[i])
{
printf("%d\n",bird[i]);
p=true;
break;
}
}
if(p)
continue;
else
{
if(bird[1] == last[2])
printf("%d\n",bird[1] );
else if(bird[n] == first[n-1])
printf("%d\n",bird[n] );
else
printf("CAUTION: NO BIRDLIKE\n");
}
}
return 0;
}
- NOJ [1173] Birdlike Angry Pig
- NOJ [1173] Birdlike Angry Pig
- nbut [1173] Birdlike Angry Pig 找出某个数使得等于其它所有数的&操作
- NBUT 2012 Summer Training -1 / [B] Birdlike Angry Pig
- Noj
- pig
- pig
- Pig
- Pig
- Pig
- Pig
- Pig
- pig
- Why is China angry?
- Angry Grammar Nazi
- BNU33647:Angry Grammar Nazi
- angry Birds 学习札记
- Angry Grammar Nazi
- NOJ [1269] Kha\'Zix\'s Skull
- 一天一到算法题——乘积分析
- NOJ [1306] Divide The Apples
- 如何观看Netflix的美国另一个国家
- NOJ [1369] A Breaking Computer
- NOJ [1173] Birdlike Angry Pig
- NOJ [1295] About Loop
- NOJ [1289] Will TT Get Snacks?
- 悲剧!中小企业惨痛的外训经历!
- NOJ [1148] Creating Palindrome
- POJ Stars
- Nginx配置文件nginx.conf中文详解(总结)
- sp3
- POJ To the Max