杭电6276:点我
A.Easy h-index
比赛题目:
http://acm.hdu.edu.cn/downloads/2018ccpc_hn.pdf
The h-index of an author is the largest h where he has at least h papers with citations not less than h.
Bobo has published many papers.
Given a0,a1,a2,…,an which means Bobo has published ai papers with citations exactly i, find the h-index of Bobo.
Input
The input consists of several test cases and is terminated by end-of-file.
The first line of each test case contains an integer n.
The second line contains (n+1) integers a0,a1,…,an.
Output
For each test case, print an integer which denotes the result.
Constraint
- 1≤n≤2⋅105
- 0≤ai≤109
- The sum of n does not exceed 250,000.
Sample Input
1
1 2
2
1 2 3
3
0 0 0 0
Sample Output
1
2
0
记录一下后缀和
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
int t;
while(scanf("%d",&t)!=EOF){
int sum=0;
int *a=new int[t+1];
for(int i=0;i<=t;i++){
scanf("%d",&a[i]);
}
for(int i=t;i>=0;i--){
sum+=a[i];
if(sum>=i){
printf("%d\n",i);
break;
}
}
}
}
杭电6277:点我
B Higher h-index
Problem Description
The h-index of an author is the largest h where he has at least h papers with citations not less than h.
Bobo has no papers and he is going to publish some subsequently.
If he works on a paper for x hours, the paper will get (a⋅x) citations, where a is a known constant.
It’s clear that x should be a positive integer.
There is also a trick – one can cite his own papers published earlier.
Given Bobo has n working hours, find the maximum h-index of him.
Input
The input consists of several test cases and is terminated by end-of-file.
Each test case contains two integers n and a.
Output
For each test case, print an integer which denotes the maximum h-index.
Constraint
- 1≤n≤109
- 0≤a≤n
- The number of test cases does not exceed 104.
Sample Input
3 0
3 1
1000000000 1000000000
Sample Output
1
2
1000000000
Hint
For the first sample, Bobo can work
papers for
hour each.
With the trick mentioned, he will get papers with citations
. Thus, his
-index is
.
For the second sample, Bobo can work papers for and hours respectively. He will get papers with citations . Thus, his -index is .
至少有h个论文引用次数不低于h,所以要论文量尽量多,平摊n小时写成n篇论文;此时n篇论文的引用数为a,a+1,a+2,…,a+n-1,引用数为a+i时,引用数大于等于它的论文有n-i篇,设h为a+i,令a+i=n-i得i=(n-a)/2,所以h=a+(n-a)/2=(n+a)/2;
#include<iostream>
int main(){
int a,b;
while(scanf("%d %d",&a,&b)!=EOF){
printf("%d\n",(a+b)/2);
}
}
杭电6281:点我
F.Sorting
Problem Description
Bobo has n tuples (a1,b1,c1),(a2,b2,c2),…,(an,bn,cn).
He would like to find the lexicographically smallest permutation p1,p2,…,pn of 1,2,…,n such that for i∈{2,3,…,n} it holds that
api−1+bpi−1api−1+bpi−1+cpi−1≤api+bpiapi+bpi+cpi.
Input
The input consists of several test cases and is terminated by end-of-file.
The first line of each test case contains an integer n.
The i-th of the following n lines contains 3 integers ai, bi and ci.
Output
For each test case, print n integers p1,p2,…,pn seperated by spaces.
DO NOT print trailing spaces.
Constraint
- 1≤n≤103
- 1≤ai,bi,ci≤2×109
- The sum of n does not exceed 104.
Sample Input
2
1 1 1
1 1 2
2
1 1 2
1 1 1
3
1 3 1
2 2 1
3 1 1
Sample Output
2 1
1 2
1 2 3
可以开long double 过
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
struct node{
long double fen;
int index;
};
int cmp(node a,node b){
if(a.fen==b.fen){
return a.index<b.index;
}else{
return a.fen<b.fen;
}
}
int main(){
int n;
while(scanf("%d",&n)!=EOF){
node a[1010];
int d,b,c,i;
for(i=0;i<n;i++){
scanf("%d %d %d",&d,&b,&c);
long double t=d*1.0;
t+=b*1.0;
a[i].fen=t/(t+c*1.0);
a[i].index=i+1;
}
sort(a,a+n,cmp);
for(int i=0;i<n;i++){
printf("%d%c",a[i].index,i==n-1?'\n':' ');
}
}
}
还可以化成乘积,如x.a+x.b/(x.a+x.b+x.c)与y.a+y.b/(y.a+y.b+y.c) 比较,化成乘积(x.a+x.b)(y.a+y.b+y.c)和(y.a+y.b)(x.a+x.b+x.c)比较,实际就是通分,但是会爆掉unsigned long long ,这样的话就把乘积化简,得到x.a*y.c+x.b*y.c和y.a*x.c+y.b*x.c,这样就不会爆unsigned long long 啦
#include<iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
using namespace std;
struct Tuple{
long long a,b,c;
int ind;
}tup[100010];
bool cmp(Tuple x,Tuple y){
unsigned long long l=x.a*y.c+x.b*y.c;
unsigned long long r=y.a*x.c+y.b*x.c;
if(l==r) return x.ind<y.ind;
return l<r;
}
int main(){
int n;
while(scanf("%d",&n)!=EOF){
for(int i=1;i<=n;i++){
cin>>tup[i].a>>tup[i].b>>tup[i].c;
tup[i].ind=i;
}
sort(tup+1,tup+1+n,cmp);
for(int i=1;i<=n;i++){
if(i!=1) printf(" ");
cout<<tup[i].ind;
}
printf("\n");
}
return 0;
}
杭电 6282:点我
G.String Transformation
分析:发现大佬们真是啥都会啊,这个题目一看,大佬就知道用异或,主要是消掉aa,bb,就是两个字符串简化后,要一样,但是ab与ba没关系,因为是可以相互转化的,ab中间插入一个abab再简化就是ba了,所以最重要的还是字母c,个数要一样,两个字符串简化后c的相对位置要一样,所以只有记录以c,和以c分段的集合即可,化简后为a,b,ab,ba,只需统计a,b数量即可,所以用到异或。
#include<iostream>
#include<cstdio>
using namespace std;
string count(string s){
string mod="";
char sum='a';
for(int i=0;s[i];i++){
if(s[i]=='c'){
mod+=sum,sum='a';
}
else{
sum=sum^s[i];
}
}
mod+=sum;
return mod;
}
int main(){
string s1,s2;
while(cin>>s1>>s2){
puts(count(s1).compare(count(s2))==0?"Yes":"No");
}
}
其余的以后再更