2020牛客暑期多校训练营(第十场)解题报告(更新中)

2020牛客暑期多校训练营(第十场)

A:Permutation

直接暴力模拟就好了

#include 
#define rep(i,a,b) for(int i=a;i
#define T int t ;cin >> t;while(t--)
using namespace std ;
typedef long long ll;
typedef unsigned long long ull;
ll p ;
inline ll gcd(ll a,ll b){return b == 0? a:gcd(b, a % b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll Mode(ll a, ll b, ll mode)    {ll sum = 1;if(mode == 1)return 0 ;while (b) {if (b & 1) {sum = (sum * a) % mode;b--;}b /= 2;a = a * a % mode;}return sum;}
const int maxn = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const double eps = 1e-11;
ll a[maxn] ;
ll b[maxn] ;
int main(){
	T{
		scanf("%lld",&p) ;
		memset(a,0,sizeof(a)) ;
		memset(b,0,sizeof(b)) ;
		ll cnt = 0 ;
		ll flag = 1 ;ll x , y ;
		x = y = 1 ;
		while(cnt < p-1){
			if(a[x] == 0){
				cnt++ ;
				a[x]++ ;
				b[cnt] = x ;
			}
			else{
				if(a[y] == 0){
					x = y ;
					cnt++ ;
					a[x]++ ;
					b[cnt] = x ;
				}
				else{
					flag = 0 ;
					break ;
				}
			}
			y = x * 3 % p ;
            x = x * 2 % p ;
		}
		if(flag){
			for(int i = 0 ; i < cnt ; i++){
				if(i) printf(" ") ;
				printf("%lld",b[i+1]) ;
			}
		}
		else{
			printf("-1") ;
		}
		printf("\n") ;
	}
	return 0 ;
}

E:Game

思路:
核心思路

ans = max(ans,y) ;
#include 
#define rep(i,a,b) for(int i=a;i
#define T int t ;cin >> t;while(t--)
using namespace std ;
typedef long long ll;
typedef unsigned long long ull;
inline ll gcd(ll a,ll b){return b == 0? a:gcd(b, a % b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll Mode(ll a, ll b, ll mode)    {ll sum = 1;if(mode == 1)return 0 ;while (b) {if (b & 1) {sum = (sum * a) % mode;b--;}b /= 2;a = a * a % mode;}return sum;}
const int maxn = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const double eps = 1e-11;
const ll mod = 1e9 + 7;
ll  n ;
ll a[maxn] ;
int main()
{
	T{
		scanf("%lld",&n) ;
		ll ans = 0 ;ll sum = 0 ;
		for(int i= 1 ; i <= n ; i++)
		{
			ll x;
			scanf("%lld",&x) ;
			sum+=x ;
			ll y =ceil((sum+0.0)/i) ;
			ans = max(ans,y) ;
		}
		printf("%lld\n",ans) ;
		
	}
	return 0 ;
}

I:Tournament

题意:
求出球队的最短逗留总时间。

代码:

#include 
#define rep(i,a,b) for(int i=a;i
#define T int t ;cin >> t;while(t--)
using namespace std ;
typedef long long ll;
typedef unsigned long long ull;
ll n ;
int vis[305][305] ;
int main() {
	T {
		memset(vis,0,sizeof(vis)) ;
		scanf("%lld",&n) ;
		for(int i = 1 ; i <=n ; i++) {
			for(int j =  1 ; j < i  ; j++) {
				if(j-1 <= n-i) {
					printf("%d %d\n",i,j) ;
					vis[i][j] = 1 ;
                    vis[j][i] = 1 ;
				}
			}
		}
		for(int i = 1 ; i <=n ; i++) {
			for(int j = i+1 ; j <= n ; j++) {
				if(!vis[i][j]) {
					vis[i][j] = 1 ;
                    vis[j][i] = 1 ;
					printf("%d %d\n",i,j) ;
				}
			}
		}
	}
	return  0;
}

你可能感兴趣的:(牛客多校,题解)