Codeforces #443 (div 2)

A. Borya’s Diagnosis

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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 3 and 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.

题意:第i个人可以走到a_i+k*b_i点,每个人走到的点不能冲突,且走到的点单调上升。问按给定的输入顺序,走的最远的人最近点在哪里。

思路:直接模拟。

#include<cstdio>
using namespace std;
#define     N       100005

int i,j,k,l,n,m,ans,a[N],b[N];

int main()
{
    scanf("%d",&n);
    for (i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
    ans=a[1];
    for (i=2;i<=n;i++)
    {
        if (a[i]<=ans) a[i]+=(ans-a[i])/b[i]*b[i];
        if (a[i]<=ans) a[i]+=b[i];
        ans=a[i];
    }
    printf("%d",ans);
    return 0;
}

B. Table Tennis

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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.

题意:有n个人,每个人有一个实力值a_i,每一轮的前两个人进行战斗,实力小的被排到最后,问第一个赢下m轮的人的实力值。

思路:我们发现当战斗次数超过n时,站在第一个的一定是实力最强的人,因此我们的枚举是有上界的。然后直接模拟即可,注意一个人输的时候胜者胜场数也要+1

#include<cstdio>
using namespace std;
#define     N       10005

int i,j,k,l,n,a[N],t;
long long m;

int main()
{
    scanf("%d%I64d",&n,&m);
    for (i=1;i<=n;i++) scanf("%d",&a[i]);
    for (j=1;j<=1000000;j++)
    {
        if (a[1]>a[2])
        {
            t=a[2];
            for (i=2;i<n;i++) a[i]=a[i+1];
            a[n]=t;
            k++;
            if ((long long)k>=m)
            {
                printf("%d",a[1]);
                return 0;
            }
        }
        else
        {
            t=a[1];
            for (i=1;i<n;i++) a[i]=a[i+1];
            a[n]=t;
            k=1;
        }
    }
    printf("%d\n",a[1]);
}

C. Short Program

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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

input
3
& 1
& 3

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.

题意:给你一些位运算操作,求一个长度不长于5的对于0-1023都成立的等价操作序列

思路:由于他只要求0-1023,我们可以对10位二进制位分别进行操作。对于每一位的运算之后我们能找到一个能够拟合的操作方式,直接模拟即可

#include<cstdio>   
using namespace std;
#define     N       500005

int i,j,k,l,n,m,z1,z2,p,q,t,ans1,ans2,ans3;
char s[N][5];
int x[N];

int main()
{
    scanf("%d",&n);
    for (i=1;i<=n;i++)
    {
        scanf("%s%d",&s[i],&x[i]);
    }
    for (i=0,q=1;i<=9;i++,q<<=1)
    {
        z1=0;
        for (j=1;j<=n;j++)
        {
            t=0;if (x[j]&q) t=1;
            if (s[j][0]=='&') z1&=t;
            if (s[j][0]=='|') z1|=t;
            if (s[j][0]=='^') z1^=t;
        }
        t=0;z2=1;
        for (j=1;j<=n;j++)
        {
            t=0;if (x[j]&q) t=1;
            if (s[j][0]=='&') z2&=t;
            if (s[j][0]=='|') z2|=t;
            if (s[j][0]=='^') z2^=t;
        }
        if (z1==0&&z2==0)
        {
            ans2+=q;
            ans3+=q;
        }
        if (z1==1&&z2==0)
        {
            ans3+=q;
        }
        if (z1==1&&z2==1)
        {
            ans2+=q;
        }
    }
    if (ans1) p++;
    if (ans2) p++;
    if (ans3) p++;
    printf("%d\n",p);
    if (ans1) printf("& %d\n",ans1);
    if (ans2) printf("| %d\n",ans2);
    if (ans3) printf("^ %d\n",ans3);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
蛋白质是生物体中普遍存在的一类重要生物大分子,由天然氨基酸通过肽键连接而成。它具有复杂的分子结构和特定的生物功能,是表达生物遗传性状的一类主要物质。 蛋白质的结构可分为四级:一级结构是组成蛋白质多肽链的线性氨基酸序列;二级结构是依靠不同氨基酸之间的C=O和N-H基团间的氢键形成的稳定结构,主要为α螺旋和β折叠;三级结构是通过多个二级结构元素在三维空间的排列所形成的一个蛋白质分子的三维结构;四级结构用于描述由不同多肽链(亚基)间相互作用形成具有功能的蛋白质复合物分子。 蛋白质在生物体内具有多种功能,包括提供能量、维持电解质平衡、信息交流、构成人的身体以及免疫等。例如,蛋白质分解可以为人体提供能量,每克蛋白质能产生4千卡的热能;血液里的蛋白质能帮助维持体内的酸碱平衡和血液的渗透压;蛋白质是组成人体器官组织的重要物质,可以修复受损的器官功能,以及维持细胞的生长和更新;蛋白质也是构成多种生理活性的物质,如免疫球蛋白,具有维持机体正常免疫功能的作用。 蛋白质的合成是指生物按照从脱氧核糖核酸(DNA)转录得到的信使核糖核酸(mRNA)上的遗传信息合成蛋白质的过程。这个过程包括氨基酸的活化、多肽链合成的起始、肽链的延长、肽链的终止和释放以及蛋白质合成后的加工修饰等步骤。 蛋白质降解是指食物中的蛋白质经过蛋白质降解酶的作用降解为多肽和氨基酸然后被人体吸收的过程。这个过程在细胞的生理活动中发挥着极其重要的作用,例如将蛋白质降解后成为小分子的氨基酸,并被循环利用;处理错误折叠的蛋白质以及多余组分,使之降解,以防机体产生错误应答。 总的来说,蛋白质是生物体内不可或缺的一类重要物质,对于维持生物体的正常生理功能具有至关重要的作用。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值