Codeforces Round #443 (Div. 2) A-C 题解
来源:互联网 发布:sql查询sequence 编辑:程序博客网 时间:2024/06/07 15:17
好久不写博客,把最近的cf题解补回来。
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 dayssi, 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.
32 21 22 2
4
210 16 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.
cf的题就是英语难懂,这次的题还好些,毕竟看示例几乎就能看出题意。第一个题就是医生上班的时间类似于等差数列,要求严格按照输入顺序来对数据进行模拟,就是简单的模拟而已。
代码实现:
#include<iostream>#include<algorithm>#include<cstring>#include<cmath>#include<queue>#include<set>#include<cstdio>#define ll long long#define mset(a,x) memset(a,x,sizeof(a))using namespace std;const double PI=acos(-1);const int inf=0x3f3f3f3f;const double esp=1e-6;const int maxn=1e6+5;const int mod=1e9+7;int dir[4][2]={0,1,1,0,0,-1,-1,0};ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}ll lcm(ll a,ll b){return a/gcd(a,b)*b;}ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}struct node{int s,d;}p[10000];int main(){int n,i,j,k;while(cin>>n){for(i=0;i<n;i++)cin>>p[i].s>>p[i].d;int ans=p[0].s;for(i=1;i<n;i++){while(p[i].s<=ans)p[i].s+=p[i].d;ans=p[i].s;}cout<<ans<<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.
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 21 2
2
4 23 1 2 4
3
6 26 5 3 1 2 4
6
2 100000000002 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
又是一道模拟题,题意是有n个人,每个人都有一个能力值,从第一个人开始,依次跟后面的人进行比赛,输了的去队伍的最尾端,问第一个能连胜k场的人是哪个。
k<=10^12,其实也没那么可怕嘛,n最大不才500,只要k大于等于n输出的一定是最大的那个数,因为只有它才可以连续赢,当k小于n时,模拟就ok了,设置一个计数器从0开始计数,如果它大于前者,达到k-1就可以了。
代码实现:
#include<iostream>#include<algorithm>#include<cstring>#include<cmath>#include<queue>#include<set>#include<cstdio>#define ll long long#define mset(a,x) memset(a,x,sizeof(a))using namespace std;const double PI=acos(-1);const int inf=0x3f3f3f3f;const double esp=1e-6;const int maxn=1e6+5;const int mod=1e9+7;int dir[4][2]={0,1,1,0,0,-1,-1,0};ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}ll lcm(ll a,ll b){return a/gcd(a,b)*b;}ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}int map[505];int main(){ll n,k,i,j,ans;while(cin>>n>>k){for(i=0;i<n;i++)cin>>map[i];if(k>=n){sort(map,map+n);cout<<map[n-1]<<endl;continue;}int flag=1;for(i=0;i<n&&flag;i++){if(map[i]<k)continue;int sum=0;if(i&&map[i-1]<map[i])sum=1;for(j=1;j<=k-sum;j++){int temp=(i+j)%n;if(map[i]<map[temp])break;if(j==k-sum){flag=0;ans=map[i];break;}}}cout<<ans<<endl;}return 0;}
- Codeforces Round #443 (Div. 2) A-C 题解
- Codeforces Round #241 (Div. 2) A B C题解
- Codeforces Round #292 (Div. 2) A,B,C,D 题解
- Codeforces Round #304 (Div. 2) A,B,C题解
- Codeforces Round #364 (Div. 2)(A,B,C,D) 题解
- Codeforces Round #377 (Div. 2)部分题解A+B+C!
- Codeforces Round #388 (Div. 2) A,B,C,D 题解
- Codeforces Round #395 (Div. 2) A,B,C,D 题解
- Codeforces Round #429 (Div. 2) A-C题解
- Codeforces Round #435 (Div. 2) A-C题解+D代码
- Codeforces Round #436 div 2 A B C D 题解
- Codeforces Round #439 (Div. 2) A-C题解
- Codeforces Round #439 (Div. 2) A-C题解
- Codeforces Round #444 (Div. 2) A-C 题解
- Codeforces Round #446 (Div. 2) A-C 题解
- Codeforces Round #447 (Div. 2) A-C题解
- Codeforces Round #449 (Div. 2) A-C题解
- Codeforces Round #450 (Div. 2) A-C题解
- Menu菜单的使用
- printf函数的用法
- 用matlab写Arcgis的shp文件
- KMP
- zoj-1067
- Codeforces Round #443 (Div. 2) A-C 题解
- HTML5概述
- 我的在线笔记1flese网站发布
- 03-树3 Tree Traversals Again(25 分)
- 前端学习的一些基本常识
- 如何配置Tomcat使用https协议
- C语言有以下几种取整方法
- MATLAB\Simulink与python之间相互调用
- 腾讯云机器学习平台技术负责人:揭秘深度学习平台DI-X背后的秘密