2018湘潭邀请赛 AFK题解 其他待补...

A.HDU6276:Easy h-index

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1181    Accepted Submission(s): 415


Problem Description
比赛题目:
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

1n2105
0ai109
* 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
 
 
题意:
  题意看了很久看晕了...
  题目意思是:从 a到 a给 n+1 个数,每个数 a表示被引用次数等于 i 的文章数量。现在要在0~n 中找到满足 被引用次数大于等于h的论文至少有h张中最大的h。
题解:
   从后往前遍历,计算后缀和,当和大于当前下标时直接输出就行了。
#include <stdio.h>
#include <string.h>
#include <string>
#include <map>
#include <queue>
#include <iostream>
#include <algorithm>
#define ll long long
#define exp 1e-8
using namespace std;
const int N = 2e5 +5;
const int INF = 2e9+5;
const int mod = 1e9+7;
ll a[N];
int main() {
    int n;
    while (~scanf("%d",&n)){
        for (int i = 0; i <= n; i++) {
            scanf("%lld",&a[i]);
        }
        ll ans = 0;
        for (int i =n; i >= 0; i--){
            ans += a[i];
            if (ans >= i){
                printf("%d\n",i);
                break ;
            }
        }
    }
    return 0;
}
View Code

F.HDU6281:Sorting

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1482    Accepted Submission(s): 407


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

 
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 aibi and ci.
 
Output
For each test case, print  n integers p1,p2,,pn seperated by spaces.
DO NOT print trailing spaces.

## Constraint

1n103
1ai,bi,ci2×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
 
 
题意:
   给你n个元组要你按要求排序。
 
题解:
  直接sort就行了。不过要注意:
  1.在按这个公式比较时最好不要用除法(可能会丢失精度)。
  2.用乘法是可能会爆unsigned long long,所以我们要先进行约分再来比较。
 
#include <stdio.h>
#include <string.h>
#include <string>
#include <map>
#include <queue>
#include <iostream>
#include <algorithm>
#define ll long long
#define exp 1e-8
using namespace std;
const int N = 1e3 +5;
const int INF = 2e9+5;
const int mod = 1e9+7;
struct node{
    int id;
    ll a,b,c;
}p[N];
bool cmp(node x,node y){
    ll ans1 = (x.a+x.b)*y.c;
    ll ans2 = (y.a+y.b)*x.c;
    if (ans1 == ans2){
        return x.id<y.id;
    }
    return ans1 < ans2;
}
int main() {
    int n;
    while (~scanf("%d",&n)){
        for (int i = 0; i < n; i++) {
            p[i].id = i + 1;
            scanf("%lld%lld%lld",&p[i].a,&p[i].b,&p[i].c);
        }
        sort(p,p+n,cmp);
        for (int i = 0; i < n-1; i++){
            printf("%d ",p[i].id);
        }
        printf("%d\n",p[n-1].id);
    }
    return 0;
}
View Code
 
 

K.HDU6286:2018

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 908    Accepted Submission(s): 457


Problem Description
Given  a,b,c,d, find out the number of pairs of integers (x,y) where axb,cyd and xy is a multiple of 2018.
 

Input
The input consists of several test cases and is terminated by end-of-file.

Each test case contains four integers  a,b,c,d.
 

Output
For each test case, print an integer which denotes the result.

## Constraint

1ab109,1cd109
* The number of tests cases does not exceed 104.
 

Sample Input
1 2 1 2018
1 2018 1 2018
1 1000000000 1 1000000000
 

Sample Output
3
6051
1485883320325200
 
 
题意:
    问有多少对有序数组(x,y)(x∈[a,b],y∈[c,d])使得x*y是2018的倍数
 
 
题解:
  我们可以分类讨论,将[a,b]区间的数分为4种:
  1.x1:2018的倍数,此时x1中的数与[c,d]区间的任意一个数相乘都能组成2018的倍数。  
    ans += x1 * [c,d]中数个数
  2.x2:除x1以外的偶数(因为x1已经计算过了,不减去会重复计算),此时x2中的数与[c,d]中1009的倍数相乘都能组成2018 的倍数。
    ans += x2 * [c,d]中1009的倍数的个数
  3.x3:1009的奇数倍(偶数倍为2018的倍数,已经计算过),此时x3中的数与[c,d]中的偶数相乘都能组成2018的倍数。
    ans += x3 * [c,d]中偶数的个数
  4.x4:除1009倍数以外的奇数,此时x4中的数与[c,d]中偶数相乘都能组成2018的倍数。
    ans += x4 * [c,d]中2018的倍数的个数
 
#include <stdio.h>
#include <string.h>
#include <string>
#include <map>
#include <queue>
#include <iostream>
#include <algorithm>
#define ll long long
#define ull unsigned ll
#define exp 1e-8
using namespace std;
const int N = 1e3 +5;
const int INF = 2e9+5;
const int mod = 1e9+7;
int main() {
    ll a,b,c,d;
    while (cin>>a>>b>>c>>d){
        ll ans = 0;
        ll x1 =b/2018 - (a-1)/2018; //a~b中2018的倍数 × all
        ans += x1 * (d-c+1);
        ll x2 = b/2-(a-1)/2 - x1; //a~b中偶数(除了x1)的个数 × 1009倍数
        ans += x2 * (d/1009 - (c-1)/1009);
        ll x3 = b/1009 - (a-1)/1009 - x1;//a~b中1009的奇数倍 × 偶数
        ans += x3 * (d/2 - (c-1)/2);
        ll x4 = (b-a+1) - (b/2-(a-1)/2) - x3;//a~b中奇数的个数 × 2018倍数
        ans += x4 * (d/2018 - (c-1)/2018);
        //printf("%lld %lld %lld %lld \n",x1,x2,x3,x4);
        cout << ans << '\n';
    }
    return 0;
}
View Code
 
 
 
 
 
 
 
 
 

猜你喜欢

转载自www.cnblogs.com/l999q/p/10664989.html