http://codeforces.com/contest/879/
It seems that Borya is seriously sick. He is going visit n doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Borya should first visit doctor 1, then doctor 2, then doctor 3and so on). Borya will get the information about his health from the last doctor.
Doctors have a strange working schedule. The doctor i goes to work on the si-th day and works every di day. So, he works on days si, si + di, si + 2di, ....
The doctor's appointment takes quite a long time, so Borya can not see more than one doctor per day. What is the minimum time he needs to visit all doctors?
First line contains an integer n — number of doctors (1 ≤ n ≤ 1000).
Next n lines contain two numbers si and di (1 ≤ si, di ≤ 1000).
Output a single integer — the minimum day at which Borya can visit the last doctor.
3 2 2 1 2 2 2
4
2 10 1 6 5
11
In the first sample case, Borya can visit all doctors on days 2, 3 and 4.
In the second sample case, Borya can visit all doctors on days 10 and 11.
题目很简单,只要求每一行的最小值,且这个最小值满足比上一行的值大即可
#include <iostream>
using namespace std;
const int maxn=1005;
int main()
{
int n;
cin>>n;
int s[maxn],d[maxn];
cin>>s[0]>>d[0];
for(int i=1;i<n;i++)
{
cin>>s[i]>>d[i];
while(s[i]<=s[i-1])
{
s[i]+=d[i];
}
}
cout<<s[n-1]<<endl;
return 0;
}
n people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins k games in a row. This player becomes the winner.
For each of the participants, you know the power to play table tennis, and for all players these values are different. In a game the player with greater power always wins. Determine who will be the winner.
The first line contains two integers: n and k (2 ≤ n ≤ 500, 2 ≤ k ≤ 1012) — the number of people and the number of wins after which a player leaves, respectively.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ n) — powers of the player. It's guaranteed that this line contains a valid permutation, i.e. all ai are distinct.
Output a single integer — power of the winner.
2 2 1 2
2
4 2 3 1 2 4
3
6 2 6 5 3 1 2 4
6
2 10000000000 2 1
2
Games in the second sample:
3 plays with 1. 3 wins. 1 goes to the end of the line.
3 plays with 2. 3 wins. He wins twice in a row. He becomes the winner.
题意:
有一个队列的人打乒乓球,首先队列的最前面的两个人开始比赛,输了的人回到队尾,队首的人接着比赛,知道有一个人连续赢了k场比赛为止
思路:
很明显,如果开队列模拟做的话肯定超时,所以要想一些小技巧
开一个值maxnnum,记录当前最强的选手是谁,再用另一个值big,记录他连胜的次数
置队列最开始的人为maxnnum,如果赢了,则big++;输了maxnnum赋值为赢对手,big赋值为1;
#include <iostream>
using namespace std;
typedef long long ll;
const int maxn=510;
int main()
{
ll a[maxn];
ll n,k;
cin>>n>>k;
cin>>a[0];
ll maxnnum=a[0];
ll big=0;
ll flag=0;
for(ll i=1;i<n;i++)
{
cin>>a[i];
if(maxnnum>a[i])
{
big++;
if(big==k)
{
flag=1;
break;
}
}
else
{
big=1;
maxnnum=a[i];
}
}
cout<<maxnnum<<endl;
return 0;
}
给你一串位运算
计算x与这些位运算以后的结果
注意样例中给的答案只是特殊值,还有其他值也是正确的
当时深夜十一点多写的,写到后面就崩掉了,主要是自己位运算的基础功还不过关
今天早上看了大佬的博客,思路看懂了,做法还没深刻理解
给你位运算,让你写操作
对于每一位
^1 取反
&0 清空
|1 赋值
那就搞这三个操作好了
#include <cstdio>
const int N=5e5+5;
char a[N];
int b[N],F[10][2],fh[10][4];
int main()
{
int n;
scanf("%d",&n);
for(int i=1; i<=n; i++)
{
getchar();
scanf("%c %d",&a[i],&b[i]);
}
int x=1;
for(int i=0; i<10; i++)
{
int y=x,z=0;
for(int j=1; j<=n; j++)
{
if(a[j]=='|')
z|=b[j],y|=b[j];
else if(a[j]=='&')
z&=b[j],y&=b[j];
else
z^=b[j],y^=b[j];
}
y>>=i,z>>=i;
F[i][1]=y&1,F[i][0]=z&1;
x<<=1;
}
int f1=0,f2=0,f3=0;
for(int i=0; i<10; i++)
{
if(F[i][1]&&!F[i][0])
fh[i][0]=1;
else if(F[i][1]&&F[i][0])
fh[i][0]=1,fh[i][1]=1;
else if(!F[i][1]&&!F[i][0])
fh[i][0]=0;
else
fh[i][0]=1,fh[i][2]=1;
}
for(int i=9; i>=0; i--)
{
f1=f1*2+fh[i][0];
f2=f2*2+fh[i][1];
f3=f3*2+fh[i][2];
}
printf("3
& %d
| %d
^ %d
",f1,f2,f3);
return 0;
}