Codeforces Round #387 (Div. 2)
来源:互联网 发布:c语言编程简单乘法 编辑:程序博客网 时间:2024/06/01 20:40
A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly n pixels.
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 pixelsb, 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.
A 【水题】:
#include<cstdio>#include<cmath>int main(){ int n;scanf("%d",&n); int x; x=0; for (int i=1;i*i<=n;i++) { if (n%i==0) { x=i; } } printf("%d %d\n",x,n/x); 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.
B【水题】 :
#include<cstdio>#include<cmath>int main(){ int n;scanf("%d",&n); char ch[300]; char cc[4]; cc[0]='A';cc[1]='C';cc[2]='G';cc[3]='T'; scanf("%s",ch); int shu[4]; for (int i=0;i<4;i++) shu[i]=0; if (n%4) { printf("===\n"); } else { for (int i=0;i<n;i++) { if (ch[i]=='A') shu[0]++; else if (ch[i]=='C') shu[1]++; else if (ch[i]=='G') shu[2]++; else if (ch[i]=='T') shu[3]++; } bool fafe=true; for (int i=0;i<4;i++) if (shu[i]>n/4) fafe=false; if (!fafe) { printf("===\n"); } else { for (int i=0;i<n;i++) { if (ch[i]=='?') { for (int j=0;j<4;j++) { if (shu[j]<n/4) { ch[i]=cc[j]; shu[j]++; break; } } } } printf("%s\n",ch); } } return 0;}
C 【模拟】:
#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>using namespace std;struct node{ int t,k,d,hao,sum;}pp[100200];bool cmp1(node x, node y){ return x.t<y.t;}bool cmp2(node x, node y){ return x.hao<y.hao;}int main(){ int n,q;scanf("%d%d",&n,&q); for (int i=0;i<q;i++) { scanf("%d%d%d",&pp[i].t,&pp[i].k,&pp[i].d); pp[i].hao=i;pp[i].sum=0; } sort(pp,pp+q,cmp1); int qi[120]; for (int i=0;i<=n;i++) qi[i]=0; for (int i=0;i<q;i++) { int lp=0; for (int j=1;j<=n;j++) { if (qi[j]<pp[i].t) lp++; } if (lp>=pp[i].k) { for (int j=1;j<=n;j++) { if (qi[j]<pp[i].t) { pp[i].k--;pp[i].sum+=j; qi[j]=pp[i].t+pp[i].d-1; } if (pp[i].k==0) break; } } else pp[i].sum=-1; } sort(pp,pp+q,cmp2); for (int i=0;i<q;i++) printf("%d\n",pp[i].sum); return 0;}
D :
orz ------ing------
开始是夏季---还有最后一段区间需要最后考虑---
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. After k 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<cstdio>#include<cstring>#include<algorithm>using namespace std;struct node{ int k,ll,you;}pp[200000];bool a[300000];bool cmp(node x, node y){ if (x.you==y.you) return x.ll<y.ll; return x.you>y.you;}int main(){ int n,k,lp=0,aa,kai=0; scanf("%d%d",&n,&k); for (int i=1;i<=n;i++) { scanf("%d",&aa); if (aa<0) { a[i]=false; lp++; if (!kai) kai=i; } else a[i]=true; } if (lp>k) { printf("-1\n"); } else if (lp==k) { int ans=0; if (kai) for (int i=kai;i<=n;i++) { if (i==kai) ans++; else { if (a[i]!=a[i-1]) ans++; } } printf("%d\n",ans); } else { if (!kai) { printf("0\n"); return 0; } int kk=k-lp; bool fafe=false; int kp=0; a[n+1]=false; for (int i=kai;i<=n+1;i++) { if (a[i]) { if (!fafe) { pp[kp].k=i; fafe=true; } } else { if (fafe) { pp[kp].ll=i-pp[kp].k; pp[kp].you=1; kp++; fafe=false; } } } if (a[n]) pp[kp-1].you=0; sort(pp,pp+kp,cmp); for (int i=0;i<kp;i++) { if (kk>=pp[i].ll) { for (int j=pp[i].k;j<pp[i].k+pp[i].ll;j++) a[j]=false; kk-=pp[i].ll; } } int ans=0; for (int i=kai;i<=n;i++) { if (i==kai) ans++; else { if (a[i]!=a[i-1]) ans++; } } printf("%d\n",ans); } return 0;}/*10 62 -5 1 3 0 0 -4 -3 1 0Output4Answer3Checker Logwrong answer expected '3', found '4'*//*50 36 20 17 19 15 17 3 17 5 16 20 18 9 19 18 18 2 -3 11 11 5 15 4 18 16 16 19 11 20 17 2 1 11 14 18 -8 13 17 19 9 9 20 19 20 19 5 12 19 6 9Output5Answer4Checker Logwrong answer expected '4', found '5'*/
E 【模拟】:
#include<cstdio>#include<vector>#include<cstring>#include<algorithm>using namespace std;char ch[2000000];struct node{ int cc; int shu; int ff;}pp[300000];vector <int > ve[300000];int shu[300000],wei[300000],kp,ans;void dfs(int ff,int deep,int i){ if (i==kp) return ; if (ff==0) { deep=1; pp[i].ff=ff; ans=max(ans,deep); ve[deep].push_back(i); dfs(i,deep+1,i+1); } else { if (pp[ff].shu==0) { dfs(pp[ff].ff,deep-1,i); } else { pp[ff].shu--; pp[i].ff=ff; ans=max(ans,deep); ve[deep].push_back(i); dfs(i,deep+1,i+1); } }}int main(){ scanf("%s",ch); memset(shu,0,sizeof(shu)); memset(wei,0,sizeof(wei)); int ll=strlen(ch); ch[ll]=','; ch[ll+1]=0; ll++; int lp=0; bool fafe=true,f2=true; char cha[20];int ccc=0,cl=0; kp=1;memset(cha,0,sizeof(cha)); for (int i=0;i<ll;i++) { if (ch[i]!=',') { if (fafe) { if (f2) { pp[kp].cc=i; f2=false; } } else ccc=ccc*10+ch[i]-48; } else { if (fafe) { fafe=false; cl=0; memset(cha,0,sizeof(cha)); } else { fafe=true; f2=true; pp[kp].shu=ccc; kp++;ccc=0; } } } lp=1;int x; dfs(0,0,1); printf("%d\n",ans); for (int i=1;i<=ans;i++) { int jl=ve[i].size(); for (int j=0;j<jl;j++) { x=pp[ve[i][j]].cc; while (ch[x]!=',') printf("%c",ch[x++]); printf("%c",j==jl-1?'\n':' '); } } return 0;}
- Codeforces Round #387 (Div. 2)
- Codeforces Round #387 (Div. 2)
- Codeforces Round #387 (Div. 2)
- Codeforces Round #387 (Div. 2)
- Codeforces Round #387 (Div. 2)
- Codeforces Round #387 (Div. 2)
- Codeforces Round #387 (Div. 2) A---D
- Codeforces Round #387 (Div. 2) E. Comments
- Codeforces Round #387 (Div. 2) C. Servers
- Codeforces Round #387 (Div. 2) Servers
- Codeforces Round #387 (Div. 2) E. Comments
- Codeforces Round #387 (Div. 2) C
- Codeforces Round #387 (Div. 2) A
- Codeforces Round #387 (Div. 2) C. Servers
- Codeforces Round #102 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #104 (Div. 2)
- MySQL 1130错误解决方法
- 多线程相关文章收集
- 转: windows下C++ UI库 UI神器-SOUI
- java核心技术卷一学习 2016.11.29
- Request常用方法
- Codeforces Round #387 (Div. 2)
- # **Fragment切换时重叠显示的解决办法**
- Centos6.5安装配置mongodb3.4
- ACME-TINY制作免费的HTTPS证书
- Python 异步网络爬虫 I
- 数据归一化的方法
- 基于七牛和fresco的一整套安卓图片解决方案
- ASP杂谈ONE、TWO、THREE
- html5下划手机屏幕,实现数据加载