Codeforces Round #443 (Div. 2)

本文探讨两个算法挑战问题:一是求最小访问时间问题,通过计算医生的特殊工作安排来确定病患Borya完成诊断所需的最短时间;二是位运算简化问题,目标是将复杂的位运算程序简化为不超过五行代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

 

这个题我没有看到是按顺序的,GG

按顺序之后就找到每个点的最小值就好了,就是一个不等式

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,m=0;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        int a,b;
        cin>>a>>b;
        if(m<a)m=a;
        else
        {
            ll k=(m-a)/b+1;
            m=a+k*b;
        }
    }
    cout<<m<<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.

给你n个人,如果这个人输了就到队列尾部,然后模拟下 

这个B本来队列模拟就错了,结果雪上加霜,因为我输了就意味着下一个人赢了啊,欢快的打出GG

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[1005];
int main()
{
    ll n,k;
    cin>>n>>k;
    for(int i=0; i<n; i++)
        cin>>a[i];
    ll mm=a[0],t=0;
    for(int i=1; i<n; i++)
    {
        if(t>=k)
        {
            cout<<mm;
            return 0;
        }
        if(mm>a[i])
            t++;
        else
            mm=a[i],t=1;
    }
    cout<<mm<<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.

 

 给你位运算,让你写操作

对于每一位
^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;
}

 

转载于:https://www.cnblogs.com/BobHuang/p/7741127.html

资源下载链接为: https://pan.quark.cn/s/9648a1f24758 这个HTML文件是一个专门设计的网页,适合在告白或纪念日这样的特殊时刻送给女朋友,给她带来惊喜。它通过HTML技术,将普通文字转化为富有情感和创意的表达方式,让数字媒体也能传递深情。HTML(HyperText Markup Language)是构建网页的基础语言,通过标签描述网页结构和内容,让浏览器正确展示页面。在这个特效网页中,开发者可能使用了HTML5的新特性,比如音频、视频、Canvas画布或WebGL图形,来提升视觉效果和交互体验。 原本这个文件可能是基于ASP.NET技术构建的,其扩展名是“.aspx”。ASP.NET是微软开发的一个服务器端Web应用程序框架,支持多种编程语言(如C#或VB.NET)来编写动态网页。但为了在本地直接运行,不依赖服务器,开发者将其转换为纯静态的HTML格式,只需浏览器即可打开查看。 在使用这个HTML特效页时,建议使用Internet Explorer(IE)浏览器,因为一些老的或特定的网页特效可能只在IE上表现正常,尤其是那些依赖ActiveX控件或IE特有功能的页面。不过,由于IE逐渐被淘汰,现代网页可能不再对其进行优化,因此在其他现代浏览器上运行可能会出现问题。 压缩包内的文件“yangyisen0713-7561403-biaobai(html版本)_1598430618”是经过压缩的HTML文件,可能包含图片、CSS样式表和JavaScript脚本等资源。用户需要先解压,然后在浏览器中打开HTML文件,就能看到预设的告白或纪念日特效。 这个项目展示了HTML作为动态和互动内容载体的强大能力,也提醒我们,尽管技术在进步,但有时复古的方式(如使用IE浏览器)仍能唤起怀旧之情。在准备类似的个性化礼物时,掌握基本的HTML和网页制作技巧非常
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值