GYM 101875 2018 USP-ICMC

周末的一次组队训练,让我再次感觉到自己的菜

题目链接

Problem A

题意:求最大生成树的权值和

题解:可以证明的是,我们每一个人都向接下来的第k个人连边,剩下的连第k-1个人,这样得到的边权和一定是最大的

C++版本一

#include<bits/stdc++.h>
using namespace std;
long long gcd(long long a,long long b)
{
   
    return b==0?a:gcd(b,a%b);
}
int main()
{
   
    long long n,k,ans;
    cin>>n>>k;
    long long a=gcd(n,k);
    if(a!=1) ans=(n-a)*k+(a-1)*(k-1);
    else ans=(n-1)*k;
    cout<<ans<<endl;
    return 0;
}

Problem B

题意:给你一串长度为n的数,这个数可以将后面的数挪到前面来,如果没有小于最开始的那个数的话就输出YES,否则输出NO

题解:如果后面有数字小于第一个数的话就肯定是NO了,这题的坑点就是如果前面很长一串都相同但是后面有一个比前面相同位置的数小的话也要输出NO,因为n是5e5,我们不可能检查每一个串,其实对于这个字符串,我们可以求出这个数的最小表示法的答案,如果这个字符串的最小表示法的第一个字符不是第一个的话就是NO了

C++版本一

#include<bits/stdc++.h>
using namespace std;
int n;
string s,ss;
int main()
{
   
    cin>>n>>s;
    int a,b;
    for(int i=0,j=1,k=0;i<n&&j<n&&k<n;){
   
        int t=s[(i+k)%n]-s[(j+k)%n];
        if(t==0)k++;
        else{
   
            if(t>0) i+=(k+1);
            else j+=(k+1);
            k=0;    
        }
        if(i==j) j++;
        a=i;b=j;
    }
    int tt= min(a,b);
    for(int i=tt; i<tt+n; i++)
        ss+=s[i%n];
    for(int i=0; i<n; i++)
        if(ss[i]<s[i]){
   
            cout<<"No"<<endl;
            return 0;
        }
    cout<<"Yes"<<endl;
    return 0;
}

Problem C

题意:

题解:

C++版本一

/*
*@Author:   Agnel-Cynthia
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
#include<unordered_map>
//#define DEBUG
#define RI register int
//#define endl "\n"
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=1e3+10;
const int M=1e6+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
//int t,n,m,k,p,l,r,u,v;


bool f[M];
ll p[M];
int tot = 0;
std::vector<int> v;
bool vis[3003][1003];
ll dp[3003][1003];
unordered_map<ll, ll> mp;
void init()
{
   
    f[0] = f[1] = 1;
    for(int i = 2; i < M; i++)
    {
   
        if(!f[i]) p[tot++] = i;
        for(int  j = 0; j < tot && i * p[j] < M ; j ++)
        {
   
            f[i * p[j]] = 1;
            if(i % p[j] == 0) break;

        }
    }

}

void add(ll &a, ll b)
{
   
    a += b;
    while(a >= MOD) a-=MOD;
}

void gao(ll x)
{
   
    for(int i = 0; i 
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值