杭电多校第一场

这场我和队友过了4个题

rank差不多到了两百

不算太好

第七题是有实力切的

后边不想写了

这场我水了三道水题

卡了一道题

那道题队友解决了

第一题

1/r+1/t+1/s=1

这个不定方程只有三组解,我当时没有证出,只是猜了一下结论,然后随便以讨论就好了

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M=1e9+7;
int main(){
    int T;
    cin>>T;
    while(T--){
        ll x;
        scanf("%lld",&x);
        if(x%3==0){
            printf("%lld\n",x*x*x/27);
        }else if(x%4==0){
            printf("%lld\n",x*x*x/32);
        }else printf("-1\n");
    }
}

第三题

比较简单,随便排下序,很水的一道题

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e4+10;
struct P{
    ll x,y,id;
}A[N];
bool cmp(P a,P b){
    return a.x<=b.x;
}
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        int n;
        scanf("%d",&n);
        for(int i=1;i<=n*3;++i){
            scanf("%lld%lld",&A[i].x,&A[i].y);
            A[i].id=i;
        }
        sort(A+1,A+1+3*n,cmp);
        for(int i=1;i<=n;++i){
            printf("%lld %lld %lld\n",A[3*i-2].id,A[3*i-1].id,A[3*i].id);
        }
    }
}

第十题

模拟水题,注意小数的问题

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int T;
    cin>>T;
    while(T--){
        int x,y;
        scanf("%d%d",&x,&y);
        int ans=x*60+y;
        char c;
        for(int i=1;i<=5;++i)scanf("%c",&c);
        double z;
        scanf("%lf",&z);
        if(c=='+'){
            ans+=round((z-8)*60);
        }else{
            ans-=round((z+8)*60);
        }
        ans+=3*1440;
        ans%=1440;
        if(ans/60<10) printf("0");
        printf("%d:",ans/60);
        if(ans%60<10) printf("0");
        printf("%d\n",ans%60);
    }
}

第四题

贪心算法,双指针扫一遍就好,每次不断取最小的,可以拿set来维护一下,这题把我卡了,队友代码:

#include<bits/stdc++.h>

using namespace std;

struct pp{
    int l,r;
};

int ttt,n,m,head,tail,dui[100010],tot,str[100010],pre[100010],now,o;

pp a[100010];

bool cmp(pp &a,pp &b){
    if (a.l==b.l){
        return a.r<b.r;
    }
    return a.l<b.l;
}

void jia(int k){
    tot++;
    dui[tot]=k;
    int i=tot;
    while (i>1){
        int j=i/2;
        if (dui[i]>dui[j]) break;
        swap(dui[i],dui[j]);
        i=j;
    }
}

int pop(){
    int t=dui[1];
    swap(dui[1],dui[tot]);
    tot--;
    int i=1;
    while (i*2<=tot){
        int j=i*2;
        if ((j+1<=tot)&&(dui[j+1]<dui[j]))j++;
        if (dui[i]<dui[j]) break;
        swap(dui[i],dui[j]);
        i=j;
    }
    return t;
}

int main(){
    scanf("%d",&ttt);
    while (ttt--){
        scanf("%d%d",&n,&m);
        for (int i=1;i<=m;i++){
            scanf("%d%d",&a[i].l,&a[i].r);
        }
        for (int i=1;i<=n;i++){
            dui[i]=i;
            pre[i]=i;
        }
        pre[n+1]=-1;
        tot=n;
        sort(a+1,a+m+1,cmp);
        now=1;
        for (int i=1;i<=n;i++){
            while(i>a[now].r&&now!=m){
                now++;
            }
            if (i>=a[now].l&&i<=a[now].r){
                pre[i]=a[now].l;
            }
        }
        now=1;
        tail=1;
        o=pre[tail];
        while (1){
            while (pre[tail]==o){
                str[tail]=pop();
                tail++;
            }
            o=pre[tail];
            for (int i=now;i<o;i++){
                jia(str[i]);
            }
            now=o;
            if (tail==n+1) break;
        }
        printf("%d",str[1]);
        for (int i=2;i<=n;i++){
            printf(" %d",str[i]);
        }
        printf("\n");
    }
    return 0;
}

第七题

我的算法两个log被卡了,诶似乎讲题的也是两个log,23333,上下他的代码:

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
 
//int a[101000];
int _;
ll n;
ll mul(ll a,ll b) {
	a%=mod; b%=mod;
//	printf("%lld %lld %lld %lld\n",a,b,c,d);
	return a*b%mod;
}
 
 
ll mul(ll a,ll b,ll c) {
	a%=mod; b%=mod; c%=mod;
//	printf("%lld %lld %lld %lld\n",a,b,c,d);
	return a*b%mod*c%mod;
}
int main() {
	for (scanf("%d",&_);_;_--) {
		scanf("%lld",&n);
		ll l=0,r=n;
		while (l+1<r) {
			ll md=(l+r)>>1;
			if (2*md-__builtin_popcountll(md)<n) l=md; else r=md;
		}
		ll ans=(1+mul(n-1+n+1-2*r,r,(mod+1)/2))%mod;
		rep(i,0,61) {
			ll q=r/(1ll<<(i+1)),q2=r-(q<<(i+1));
			if (q2<(1ll<<i)) q2=0; else q2-=(1ll<<i);
			ans=(ans+mul(q,1ll<<i)+q2)%mod;
		}
/*		rep(k,0,r) {
			ans+=__builtin_popcount(k);
		}*/
		printf("%lld\n",ans);
	}
}

猜你喜欢

转载自blog.csdn.net/Gipsy_Danger/article/details/81173291