Codeforces Round #387 (Div. 2) A---D
来源:互联网 发布:知乎周刊合集 编辑:程序博客网 时间:2024/06/04 23:25
A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly npixels.
Your task is to determine the size of the rectangular display — the number of lines (rows) of pixels a and the number of columns of pixels b, so that:
- there are exactly n pixels on the display;
- the number of rows does not exceed the number of columns, it means a ≤ b;
- the difference b - a is as small as possible.
The first line contains the positive integer n (1 ≤ n ≤ 106) — the number of pixels display should have.
Print two integers — the number of rows and columns on the display.
8
2 4
64
8 8
5
1 5
999999
999 1001
In the first example the minimum possible difference equals 2, so on the display should be 2 rows of 4 pixels.
In the second example the minimum possible difference equals 0, so on the display should be 8 rows of 8 pixels.
In the third example the minimum possible difference equals 4, so on the display should be 1 row of 5 pixels.
#include<bits/stdc++.h>using namespace std;int main(){long long i,a,b,n;scanf("%I64d",&n);a=1;b=n;long long min=1000001; for(i=1;i<=sqrt(n*1.0);i++)//需要注意的是这里a最大就只能到根号n 否则 a不满足小于等于b { if(n%i==0) { if(n/i-i<min) { min=n/i-i; a=i;} } } b=n/a;printf("%I64d %I64d",a,b);return 0;}
The process of mammoth's genome decoding in Berland comes to its end!
One of the few remaining tasks is to restore unrecognized nucleotides in a found chain s. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, s is a string consisting of letters 'A', 'C', 'G', 'T' and characters '?'.
It is known that the number of nucleotides of each of the four types in the decoded genome of mammoth in Berland should be equal.
Your task is to decode the genome and replace each unrecognized nucleotide with one of the four types so that the number of nucleotides of each of the four types becomes equal.
The first line contains the integer n (4 ≤ n ≤ 255) — the length of the genome.
The second line contains the string s of length n — the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'.
If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes).
8AG?C??CT
AGACGTCT
4AGCT
AGCT
6????G?
===
4AA??
===
In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice.
In the second example the genome is already decoded correctly and each nucleotide is exactly once in it.
In the third and the fourth examples it is impossible to decode the genom.
#include<bits/stdc++.h>using namespace std;char s[500];int a=0,c=0,g=0,t=0,x=0;int main(){ int i,n;scanf("%d",&n); scanf("%s",s); int len=strlen(s); if(len%4) {printf("==="); } else { for(i=0;i<len;i++) {if(s[i]=='A') a++; else if(s[i]=='C') c++; else if(s[i]=='G') g++; else if(s[i]=='T') t++; else x++;}int w=len/4;if(a>w||g>w||c>w||t>w){printf("===");}else{for(i=0;i<len;i++){ if(s[i]=='?'){ if(a<w) { s[i]='A'; a++; } else if(c<w) { s[i]='C'; c++; } else if(g<w) { s[i]='G'; g++; } else if(t<w) {s[i]='T'; t++; }}}printf("%s",s);} } return 0;}
There are n servers in a laboratory, each of them can perform tasks. Each server has a unique id — integer from 1 to n.
It is known that during the day q tasks will come, the i-th of them is characterized with three integers: ti — the moment in seconds in which the task will come, ki — the number of servers needed to perform it, and di — the time needed to perform this task in seconds. All ti are distinct.
To perform the i-th task you need ki servers which are unoccupied in the second ti. After the servers begin to perform the task, each of them will be busy over the next di seconds. Thus, they will be busy in seconds ti, ti + 1, ..., ti + di - 1. For performing the task, ki servers with the smallest ids will be chosen from all the unoccupied servers. If in the second ti there are not enough unoccupied servers, the task is ignored.
Write the program that determines which tasks will be performed and which will be ignored.
The first line contains two positive integers n and q (1 ≤ n ≤ 100, 1 ≤ q ≤ 105) — the number of servers and the number of tasks.
Next q lines contains three integers each, the i-th line contains integers ti, ki and di (1 ≤ ti ≤ 106, 1 ≤ ki ≤ n,1 ≤ di ≤ 1000) — the moment in seconds in which the i-th task will come, the number of servers needed to perform it, and the time needed to perform this task in seconds. The tasks are given in a chronological order and they will come in distinct seconds.
Print q lines. If the i-th task will be performed by the servers, print in the i-th line the sum of servers' ids on which this task will be performed. Otherwise, print -1.
4 31 3 22 2 13 4 3
6-110
3 23 2 35 1 2
33
8 61 3 204 2 16 5 510 1 115 3 621 8 8
6930-11536
In the first example in the second 1 the first task will come, it will be performed on the servers with ids 1, 2 and 3 (the sum of the ids equals 6) during two seconds. In the second 2 the second task will come, it will be ignored, because only the server 4will be unoccupied at that second. In the second 3 the third task will come. By this time, servers with the ids 1, 2 and 3 will be unoccupied again, so the third task will be done on all the servers with the ids 1, 2, 3 and 4 (the sum of the ids is 10).
In the second example in the second 3 the first task will come, it will be performed on the servers with ids 1 and 2 (the sum of the ids is 3) during three seconds. In the second 5 the second task will come, it will be performed on the server 3, because the first two servers will be busy performing the first task.
#include<bits/stdc++.h>using namespace std;int book[110];struct node{int t;int k;int d;}p[100010];int main(){int i,j,n,q;while(scanf("%d %d",&n,&q)!=EOF){ memset(p,0,sizeof(p)); for(i=1;i<=q;i++)scanf("%d %d %d",&p[i].t,&p[i].k,&p[i].d); memset(book,0,sizeof(book)); for(i=1;i<=q;i++) {int sum=0; for(j=1;j<=n;j++) {if(book[j]<=p[i].t)sum++; }if(sum<p[i].k)printf("-1\n");else{int ans=0;for(j=1;j<=n;j++){if(book[j]<=p[i].t){book[j]=p[i].t+p[i].d;p[i].k--;ans+=j;}if(p[i].k==0)break;}printf("%d\n",ans);} }}return 0;}
The winter in Berland lasts n days. For each day we know the forecast for the average air temperature that day.
Vasya has a new set of winter tires which allows him to drive safely no more than k days at any average air temperature. Afterk days of using it (regardless of the temperature of these days) the set of winter tires wears down and cannot be used more. It is not necessary that these k days form a continuous segment of days.
Before the first winter day Vasya still uses summer tires. It is possible to drive safely on summer tires any number of days when the average air temperature is non-negative. It is impossible to drive on summer tires at days when the average air temperature is negative.
Vasya can change summer tires to winter tires and vice versa at the beginning of any day.
Find the minimum number of times Vasya needs to change summer tires to winter tires and vice versa to drive safely during the winter. At the end of the winter the car can be with any set of tires.
The first line contains two positive integers n and k (1 ≤ n ≤ 2·105, 0 ≤ k ≤ n) — the number of winter days and the number of days winter tires can be used. It is allowed to drive on winter tires at any temperature, but no more than k days in total.
The second line contains a sequence of n integers t1, t2, ..., tn ( - 20 ≤ ti ≤ 20) — the average air temperature in the i-th winter day.
Print the minimum number of times Vasya has to change summer tires to winter tires and vice versa to drive safely during all winter. If it is impossible, print -1.
4 3-5 20 -3 0
2
4 2-5 20 -3 0
4
10 62 -5 1 3 0 0 -4 -3 1 0
3
In the first example before the first winter day Vasya should change summer tires to winter tires, use it for three days, and then change winter tires to summer tires because he can drive safely with the winter tires for just three days. Thus, the total number of tires' changes equals two.
In the second example before the first winter day Vasya should change summer tires to winter tires, and then after the first winter day change winter tires to summer tires. After the second day it is necessary to change summer tires to winter tires again, and after the third day it is necessary to change winter tires to summer tires. Thus, the total number of tires' changes equals four.
#include<bits/stdc++.h>#define N 2*100010using namespace std;int a[N],book[N];int n,k;struct node{int l;int item;}q[N];int cmp(node x,node y){return x.l<y.l;}int main(){ int i,j;while(scanf("%d %d",&n,&k)!=EOF){memset(book,0,sizeof(book));memset(q,0,sizeof(q)); int t=0; int w=0; a[0]=1;for(i=1;i<=n;i++){ scanf("%d",&a[i]); if(a[i]<0) {t++; book[w++]=i; }}a[n+1]=-1;book[w]=n+1;if(t>k){printf("-1\n");}else{ k-=t; int ans=0; int num=0; for(i=1;i<=n;i++) { if(a[i]<0&&a[i-1]>=0) ans+=1; if(a[i]<0&&a[i+1]>=0&&i!=n) ans+=1; } if(k==0) {printf("%d\n",ans); } else { int kk=k; int m=0,sum=ans; for(j=1;j<=w;j++) {q[m].l=book[j]-book[j-1]-1;q[m].item=j;m++;} sort(q,q+m,cmp); int flag=0; for(j=0;j<m;j++) { if(q[j].l>0&&q[j].l<=k) {k-=q[j].l; ans-=2; if(q[j].item==w) {flag=1; }}if(q[j].l>0&&q[j].l<=kk&&q[j].item!=w) {kk-=q[j].l; sum-=2;} } if(flag==1) ans+=1; ans=min(ans,sum); printf("%d\n",ans); }}}return 0;}
- Codeforces Round #387 (Div. 2) A---D
- Codeforces Round #209 (Div. 2) <A-D>
- Codeforces Round #231 (Div. 2)A-D
- Codeforces Round #235 (Div. 2) A~D
- Codeforces Round #237 (Div. 2) A~D
- Codeforces Round #240 (Div. 2) A~D
- Codeforces Round #239 (Div. 2) A~D
- Codeforces Round #242 (Div. 2) <A-D>
- Codeforces Round #250 (Div. 2) A-D
- Codeforces Round #256 (Div. 2)A-D
- Codeforces Round #263 (Div. 2) A-D
- Codeforces Round #269 (Div. 2) A~D
- Codeforces Round #358 (Div. 2)A~D
- Codeforces Round #359 (Div. 2) A ~D
- Codeforces Round #364 (Div. 2)(A ~ D)
- Codeforces Round #368 (Div. 2) A~D
- Codeforces Round #369 (Div. 2) A~D
- Codeforces Round #369 (Div. 2) A~D
- BootStrap Table 获取同行不同列元素
- linux 如何自定义信号
- java等比例压缩图片
- 音频压缩工具——Speex的使用
- struts2核心概念
- Codeforces Round #387 (Div. 2) A---D
- Android去掉标题栏以及全屏显示
- ZooKeeper客户端Curator(监听篇)
- HIVE2 Error: Failed to open new session: java.lang.RuntimeException: org.apache.hadoop.ipc.RemoteExc
- Tabs
- dsp28335 IIC总结
- 第十六周oj题目计算该日是本年的第几天
- What's the difference between mvn:deploy and mvn:install commands?
- L语言编译器的设计与实现之设计篇