http://codeforces.com/contest/879/

A. Borya's Diagnosis
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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?

Input

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

Output a single integer — the minimum day at which Borya can visit the last doctor.

Examples
input
3
2 2
1 2
2 2
output
4
input
2
10 1
6 5
output
11
Note

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;
}
B. Table Tennis
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Input

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

Output a single integer — power of the winner.

Examples
input
2 2
1 2
output
2 
input
4 2
3 1 2 4
output
3 
input
6 2
6 5 3 1 2 4
output
6 
input
2 10000000000
2 1
output
2
Note

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;
}
C. Short Program
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well.

In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023.
When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned.

Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines.
Your program should return the same integer as Petya's program for all arguments from 0 to 1023.

Input

The first line contains an integer n (1 ≤ n ≤ 5·105)
— the number of lines.

Next n lines contain commands. A command consists of a character that represents the operation ("&",
"|" or "^" for AND, OR or XOR respectively), and the constant xi 0 ≤ xi ≤ 1023.

Output

Output an integer k (0 ≤ k ≤ 5)
— the length of your program.

Next k lines must contain commands in the same format as in the input.

Examples
input
3
| 3
^ 2
| 1
output
2
| 3
^ 2
input
3
& 1
& 3
& 5
output
1
& 1
input
3
^ 1
^ 2
^ 3
output
0
Note

You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation.

Second sample:

Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1.
So these two programs always give the same outputs.


题意:

给你一串位运算

计算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\n& %d\n| %d\n^ %d\n",f1,f2,f3);
return 0;
}

CodeFoces Round #443(div.2)的更多相关文章

  1. Codeforces Round #581(Div. 2)

    Codeforces Round #581(Div. 2) CF 1204 A. BowWow and the Timetable 题解:发现,$4$的幂次的二进制就是一个$1$后面跟偶数个$0$. ...

  2. Codeforces Round #334(div.2)(新增不用二分代码) B

    B. More Cowbell time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  3. Codeforces Round #342 (Div 2) 解题报告

    除夕夜之有生之年CF第一场 下午从奶奶家回到姥姥家,一看还有些时间,先吃点水果陪姥姥姥爷聊了会儿,再一看表,5:20....woc已经开场20分钟了...于是抓紧时间乱搞.. **A. Guest F ...

  4. Codeforces Round 1153(div. 2)

    这场奇差.ABCD四题.179名. 但是E在现场有213个人做出. 描述一下我在35分钟做完D后的心路历程. 首先看到这道E,第一下想到的是把所有的横向和竖向的整列(行)求出相连的个数. 然后想如何能 ...

  5. codeforces Round #389(Div.2)C Santa Claus and Robot(思维题)

    题目链接:http://codeforces.com/contest/752/problem/C 题意:给出一系列机器人的行动方向(机器人会走任意一条最短路径),问最少标记几个点能让机器人按这个 路径 ...

  6. Codeforces Round #345 (Div 2)

    最后两题是orzCJK学长帮忙代打的,不过总算是到蓝名了(上次睡迟了,只剩半个小时,结果作大死点开题目看,结果rating掉了100多),还有论代码风格的重要性!!!(没写空格被学长各种D) A题 题 ...

  7. Codeforces Round #622(Div 2)C2. Skyscrapers (hard version)

    题目链接 : C2. Skyscrapers (hard version) 题目描述 : 与上一道题类似,只是数据范围变大, 5e5, 如果用我们原来的方法,铁定是超时的. 考察点 : 单调栈,贪心, ...

  8. Codeforces Round #556(Div.1)

    A 容易发现i,i+1至少有一个数出现,于是可以让尽量多的2和奇数出现 #include<bits/stdc++.h> using namespace std; int n,s1,s2; ...

  9. codeforce Round #665(div 2)A B C

    A. Distance and Axis 题意:在一个0x轴上,给了a在0x轴上的坐标,要你放一个b点使得abs(0B - AB)的值等于 k,但是有的时候如果不移动A点就不能实现这个条件,所以要你求 ...

随机推荐

  1. App中显示html网页

    在现在的移动开发中,越来越多的web元素增加到了app里面,hybrid app可以综合native app 和 web app的长处,可以通过webView实现 htmllayout.xml: &l ...

  2. Deepin-文件目录介绍

    请参见这篇文件:来自一个强大的网站 我主要介绍的就是: 下面所列文件,全部添加进了path目录(Linux查找命令,请参见man.linux,无论是find 或者是 which等) Deepin默认可 ...

  3. C++MFC编程笔记day06 MFC向导、MFC画图类使用

    MFC画图    MFC画图类包含画图设备类和画图对象类    1 画图设备类      CDC类-父类是CObject,封装的是一般的画图设备,比如:显示器,            打印机等.    ...

  4. OSWorkFlow流程配置文件具体解释

    AbstractWorkflow>> osworkflow中有关工作流流转的全部核心代码都在AbstractWorkflow中.BasicWorkflow就是派生自它,只是这个BasicW ...

  5. Python中的shelve模块

    shelve中有用的函数就是open(),但是下面编写的数据库函数中调用路径是经常出错,如果直接调用一个从来没有用过的文件却能正常运行,暂时没有找出原因. 调用shelve.open()会返回一个sh ...

  6. 4448: [Scoi2015]情报传递|主席树|离线操作

    能够把全部的操作离线,然后树链剖分将全部人搜集情报的时间增加到主席树中,查询的时候能够直接查询搜集情报时间≤i−C[i]−1的人的个数 时间复杂度n∗log22n,空间复杂度n∗log2n #incl ...

  7. cocos2dx 3.0 显示中文及乱码解决方式

    遇到此问题第一时间在脑子里面联想到android下的strings.xml来做国际化,本文就仅仅针对解析xml来实现cocos2d-x的国际化解决乱码问题. 寻找解决方法的时候在cocos2d-x的c ...

  8. 2016/3/24 ①数据库与php连接 三种输出fetch_row()、fetch_all()、fetch_assoc() ②增删改时判断(布尔型) ③表与表之间的联动 ④下拉菜单 ⑤登陆 三个页面

    ①数据库与php连接   图表 header("content-type:text/html;charset=utf-8"); //第一种方式: //1,生成连接,连接到数据库上的 ...

  9. jsonp突破同源策略,实现跨域訪问请求

    版权声明:本文为博主原创文章,未经博主同意不得转载.如需转载请声明:[转自 http://blog.csdn.net/xiaoxian8023 ] https://blog.csdn.net/xiao ...

  10. XMU 1608 nc与加法进位 【二分】

    1608: nc与加法进位 Time Limit: 2000 MS  Memory Limit: 128 MBSubmit: 29  Solved: 27[Submit][Status][Web Bo ...