Codeforces Round #443 (Div. 2) A B C

简介: A. Borya’s Diagnosis time limit per test2 seconds memory limit per test256 megabytes inputsta...

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.

算出看完所有医生所花的时间,其实就是算出第几天看最后一名医生

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
int main(){
    int n;
    cin>>n;
    int ans=0;
    while(n--){
        int s,d;
        cin>>s>>d;
        while(s<=ans){
            s+=d;
        }
        ans=s;
    }
    cout<<ans<<endl;
    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.

题目说的是赢k场如果这个人输了就到队列尾部,但如果一次遍历后没人赢的话,赢的肯定就是那个power最多的。这题开始不知道哪被hack了。。后来发现,后一个人赢了前边的没有算进去一次。。。。

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
int main(){
    int n;
    LL k;
    cin>>n>>k;
    int a[505];
    for(int i=0;i<n;i++)
        cin>>a[i];
    LL t=0;
    int m=a[0];
    for(int i=1;i<n;i++){
        if(t>=k){
            cout<<m;
            return 0;
        }
        if(m>a[i])
            t++;
        else
            m=a[i],t=1;
    }
    cout<<m<<endl;
    return 0;
}

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

#include <cstdio>  
#include <algorithm>  
#include <cmath>  
#include <iostream>  
#include <map>   
#include <queue>  
#include <cstdlib>  
#include <cstring>  
#include <string>  
#include <ctime>  
#include <vector>  

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;

const ll MOD = 1000000009;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-8;

#define rep(i, n) for(int i=0;i<n;i++)

int v[10];
int main(){
    int N,i,j;
    scanf("%d",&N);
    for (i=0;i<10;i++) v[i]=2;
    while(N--){
        char c[2];
        int t;
        scanf("%s %d",c,&t);
        if(c[0]=='|'){
            for (i=0;i<10;i++) 
                if(t&(1<<i)) 
                    v[i]=1;
        }
        if(c[0]=='&'){
            for (i=0;i<10;i++)
                if(!(t&(1<<i))) 
                    v[i] = 0;
        }
        if(c[0]=='^')
            for(i=0;i<10;i++)
                if(t&(1<<i))
                    v[i]^= 1;
    }
    int v1=0,v2=0,v3=0;
    for(i=0;i<10;i++){
        if(v[i]==0) 
            v1|=(1<<i);
        if(v[i]==1)
            v2|=(1<<i);
        if(v[i]==3) 
            v3|=(1<<i);
    }
    printf("3\n");
    printf("| %d\n",v2);
    printf("& %d\n",1023^v1);
    printf("^ %d\n",v3);
    return 0;
}
目录
相关文章
|
Java 机器人 数据安全/隐私保护
蓝桥杯历届真题题目+解析+代码+答案(2013-2020)(JavaA、B、C组)(C++语言)(Python)
蓝桥杯历届真题题目+解析+代码+答案(2013-2020)(JavaA、B、C组)(C++语言)(Python)
681 0
|
机器学习/深度学习 自然语言处理 数据处理
通过深度学习识别情绪
通过深度学习识别情绪(Emotion Recognition using Deep Learning)是一项结合多模态数据的技术,旨在通过分析人类的面部表情、语音语调、文本内容等特征来自动识别情绪状态。情绪识别在人机交互、健康监测、教育、娱乐等领域具有广泛的应用。
1622 8
com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method add in the service
com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method add in the service
461 0
|
数据采集 安全 数据挖掘
工程监测振弦采集仪应用案例
工程监测振弦采集仪是一种用于采集结构物振动数据的仪器,它可以实现对结构物的振动进行实时监测和分析,从而确保结构物的安全和可靠性。以下是工程监测振弦采集仪的使用分析:
Qt 隐藏标题栏可拖拽,自由缩放
Qt在隐藏标题栏的情况下,实现拖拽很简单,可以看这里https://blog.csdn.net/z609932088/article/details/80865742 或者这里:https://blog.csdn.net/z609932088/article/details/50898022
395 0
Qt 隐藏标题栏可拖拽,自由缩放
|
存储 编解码 缓存
基于FPGA的异构计算在多媒体中的应用
目前处于AI大爆发时期,异构计算的选择主要在FPGA和GPU之间。 尽管目前异构计算使用最多的是利用GPU来加速,FPGA作为一种高性能、低功耗的可编程芯片,在处理海量数据时,FPGA计算效率更高,优势更为突出,尤其在大量服务器部署时,隐形的运营成本会得到显著降低。 本文来自CTAccel的研发总监周小鹏在LiveVideoStackCon2019 北京站上的分享。
778 0
基于FPGA的异构计算在多媒体中的应用
|
2天前
|
数据采集 人工智能 安全
|
11天前
|
云安全 监控 安全
|
3天前
|
自然语言处理 API
万相 Wan2.6 全新升级发布!人人都能当导演的时代来了
通义万相2.6全新升级,支持文生图、图生视频、文生视频,打造电影级创作体验。智能分镜、角色扮演、音画同步,让创意一键成片,大众也能轻松制作高质量短视频。
1020 151