18湘潭邀请赛总结(打铁)

题目链接(hdu复赛)

2018年湘潭邀请赛,在湘大举行,当时一起打的过去的,因为没出市就方便点。第一次参加现场赛,首先反省一下自己,比赛前算法先不说(没有好好搞过),就连普通的题,数学性质的题都很少刷,什么都不会,然后英语不说四六级的东西,很多专业英语词汇都没有好好了解过,主要的原因还是刷题刷少了,英文题刷少了。理所当然,成功拿下一铁,湘潭赛打铁告终。

比赛开始,这次是三个人没人一份纸质题目,拿到题目,看最后一题,k.2018发现可以做,(事实证明确实是一道水题),我就在做这题,他们看了a题,好像是k题一顿操作后提交,错了,一直到比赛结束都没做出来,后来回去看别人的题解,发现自己情况没有分析全面,其实是完全可以解出来的,真的做的太少太少了。a题最后也是没过,还有一个f题,sort,我最初的想法是用stl里的那个sort排序,只要对sort的compare函数做处理应该可以完成排序,比赛之前我看过,但是不熟悉,zxm她也看了我就交给她了,最后好像因为爆long double的问题也没做出来。
哎,菜还是菜,很多算法都不懂,数据结构也没学好,很有一段时间我都特别头疼算法,不想学,费劲,觉得自己不适合学计算机,更不适合ACM。有时候又想,不适合好像总是loser的借口!总是在后悔和偷懒的矛盾中!

A. Easy h-index

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
itations 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

题意:给定被引用次数为0~n的论文分别有几张,找到最大的h,满足被引用次数大于等于h的论文至少有h张
思路:在区间[0,n]内二分答案;或直接从n~0遍历找到第一个满足条件的h

后AC代码

#include "bits/stdc++.h"
using namespace std;
int main(){
    int a[200005];
    int n;
    int i;
    while(cin>>n){
        for(i=0;i<=n;i++)
            cin>>a[i];
        int sum=a[n];
        for(i=n;i>=0;){
            if(sum>=i){
                cout<<i<<endl;
                break;
            }
            else sum+=a[--i];
        }
        if(i<0)
            cout<<"0"<<endl;
    }
    return 0;
}

B. Higher h-index

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

Note

For the first sample, Bobo can work 3 papers for 1 hour each. With the trick mentioned,
he will get papers with citations 2,1,0. Thus, his h-index is 1.
For the second sample, Bobo can work 2 papers for 1 and 2 hours respectively.
He will get papers with citations 1+1,2+0. Thus, his h-index is 2.

题意:给定n个小时,可以用其中x(1<=x<=n)个小时写一篇论文,那么这篇论文的”既定”引用数将会是x*a(a为给定正整数);此外,已经写好的论文将会被其后写成的论文所引用,也就是说,这篇论文的总引用数将会是”既定”引用数+其后论文篇数;问在所有的写论文方案中(例如一种方案就是用n个小时写n篇论文,每篇论文各花1小时(可以得到这n篇论文的引用数)),h最大为多少(h的含义同上题)(每一种方案都对应着一个h,求这些h中的最大者)
思路:最优方案(即对应h值最大的方案)是平摊n小时写成n篇论文(证明未知);此时n篇论文的引用数为a,a+1,a+2,…,a+n-1,引用数为a+i时,引用数大于等于它的论文有n-i篇,令a+i=n-i得i=(n-a)/2,所以h=a+(n-a)/2;

后AC代码

#include<cstdio>

int main(){
   int n,a;
   while(scanf("%d%d",&n,&a)!=EOF){
    printf("%d\n",a+(n-a)/2);
   }
   return 0;
}

sorting.png

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

题意:给定n个元组(a1,b1,c1),(a2,b2,c2),…,(an,bn,cn),将其按(ai+bi)/(ai+bi+ci)的值从小到大排序,输出排序后的n个元组的原序号;
思路:编写sort里的cmp函数(形参为元组结构体元素,设为Tuple x,Tuple y),若直接算出(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

后AC代码

#include "bits/stdc++.h"
using namespace std;
struct node{
    long double a,b,c;
    int numb;
}ss[1005];

bool cmp(const node &a,const node &b){
    long double suma,sumb;
    //suma=a.a*b.c+a.b*b.c;
    //sumb=b.a*a.c+b.b*a.c;
    suma=(a.a+a.b)/(a.a+a.b+a.c);
    sumb=(b.a+b.b)/(b.a+b.b+b.c);
    if(suma!=sumb)return suma<sumb;
    return a.numb<b.numb;
}

int main(){
    int n;
    while(cin>>n){
        for(int i=0;i<n;i++){
            cin>>ss[i].a>>ss[i].b>>ss[i].c;
            ss[i].numb=i+1;
        }
        stable_sort(ss,ss+n,cmp);
        int i;
        for(i=0;i<n-1;i++)
            cout<<ss[i].numb<<" ";
        cout<<ss[i].numb<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_39520417/article/details/81073659
今日推荐