洛谷春季 ACM 多校训练

T122399 Goldbach's conjecture

题意:给你n,让你证明哥德巴赫猜想,1e9复杂度;

这题复杂度怎么算都不对,线性筛数组开不了这么大,
然后惊讶的暴力居然过了。
证法如下:

 log(n)实在很快呀,1e9也就30左右,这样算就对了;

#include<bits/stdc++.h>
using namespace std;
bool isprime(int x){
    for(int i=2;i*i<=x;i++){
    if(x%i==0)return 0;
    }
    return 1;
}
int main(){
    int n;
    cin>>n;
    for(int i=2;i*i<n;i++){
    if(isprime(i)&&isprime(n-i)){
    cout<<i<<" "<<n-i<<endl;
    break;
    }
    }


    return 0;
}
View Code

T122397 Everybody deserves a long long name

这题没水平;
不说了;

T122394 Billionaire

题意:就是问你多少天能变成亿万富翁,输出日期。

解法:二分出天数,然后用 zeller公式求日期;

这里我卡了一会,就是二分的时候,最大的区间是不能瞎选的,想想也明白,我一开始取很大,他就直接跳过正确答案了,

所以r要是sqrt(2e9),解方程得来;

二分虽然快,但你区间不能选大了,不然答案就不对了,L小了,R大了,都会跳过正确答案,

#include<bits/stdc++.h>
using namespace std;
int getId(int y, int m, int d) {
    if (m < 3) {y --; m += 12;}
    return 365 * y + y / 4 - y / 100 + y / 400 + (153 * (m - 3) + 2) / 5 + d - 307;
}
vector<int> date(int id) {
    int x = id + 1789995, n, i, j, y, m, d;
    n = 4 * x / 146097;
    x -= (146097 * n + 3) / 4;
    i = (4000 * (x + 1)) / 1461001; x -= 1461 * i / 4 - 31;
    j = 80 * x / 2447; d = x - 2447 * j / 80; x = j / 11;
    m = j + 2 - 12 * x; y = 100 * (n - 49) + i + x;
    vector<int>v;
    v.push_back(y),v.push_back(m),v.push_back(d);
    return v;
}
int m;
const int maxn=1000000000;
bool check(int x){
    int sum=m+x*(x+1)/2;
    if(sum>=maxn)return 1;
    else return 0;
}
int main(){
    int t;
    cin>>t;
    while(t--){
    int ty,tm,td;
    scanf("%d %d %d %d",&m,&ty,&tm,&td);
    int id=getId(ty,tm,td);
    int l=0,r=sqrt(2e9);
    while(l<=r){
    int mid=(r+l)/2;
    if(check(mid))r=mid-1;
    else l=mid+1;
    }
    id+=l;
    vector<int>ans=date(id);
    printf("%d %d %d\n",ans[0],ans[1],ans[2]);
    }
    // system("pause");
    return 0;
}
View Code

T122398 Final Spark

这题讲了这样一个问题:

 就是说发射一道光波,问你这个人被射中的概率。这个人半径r,跳的半径s,光波宽度w,距离d,

距离d没用,问题转化为w+2r的光波怎么切圆,覆盖面积最大。

待更新;

猜你喜欢

转载自www.cnblogs.com/littlerita/p/12387310.html
今日推荐