csust-8.7组队训练-Gym - 101968(三星题)

目录

 

A - Tree Game

B - Rectangles

C - Function

D - Two Sequences

E - Connecting Components

F - Mirror

G - TeddyBearsDay

H - Win Strategy

I - Tours

J - Restricted Vertex Cover


A - Tree Game

 Gym - 101968A 

题目链接https://codeforces.com/gym/101968/problem/A

B - Rectangles

 Gym - 101968B 

题目链接https://codeforces.com/gym/101968/problem/B

#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll maxn  = 1e6 + 7;
const ll mod = 1e9 + 7;
ll fc[maxn];
ll x[maxn],xt[maxn],y[maxn],yi[maxn];
int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	fc[0] = 1;
	for(ll i = 1;i <= maxn ;  i++)
		fc[i] = fc[i-1] * i % mod;
	ll t;
	cin >> t;
	while(t--){
		ll n ;
		cin >> n;
		n <<= 1;
		for(ll i = 1;i <= n ;i ++) cin >> x[i] >> y[i];
		for(ll i = 1;i <= n ;i ++) xt[i] = x[i];
		for(ll i = 1;i <= n ;i ++) yi[i] = y[i];
		
		sort(xt + 1, xt + n + 1);
		sort(yi + 1, yi + n + 1);
		n >>= 1;
		if(xt[n] == xt[n + 1]) { cout << 0 << endl; continue ;}
		if(yi[n] == yi[n + 1]) { cout << 0 << endl; continue ;}
		n <<= 1;
		ll a , b ;
		a = b  = 0 ;
		for(ll i = 1;i <= n;i ++){
			if(x[i] < xt[(n >> 1)+1]){
				if(y[i] < yi[(n >> 1)+1]) a++;
				else b++;
			}
		}
		cout << (long long)fc[a] * fc[b] % mod << endl;
	}
	return 0;
}

C - Function

 Gym - 101968C 

题目链接https://codeforces.com/gym/101968/problem/C

#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false)
#define ll long long
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const ll mac = 1e6 + 10;
const ll inf = 1e9 + 10;
const ll mod = 1e9 + 7;
ll tree[mac<<2];
ll a[mac], c[mac], inv[mac];
ll f[mac],fc[mac];
ll ans = 0;
int main()
{
	IOS;
	ll t, n, m;
	inv[1] = 1;
	for (ll i = 2; i <= mac; i++) {
		inv[i] = (mod - mod / i) * inv[mod % i] % mod;
	}
	f[0] = 1;
	for(int i = 1;i <= mac;i ++){
		f[i] = (ll)f[i-1]*i % mod;
	}
	fc[0] = 1;
	for(int i = 1;i <= mac ; i ++){
		fc[i] = (ll)fc[i-1]*inv[i] % mod;
	}
	cin >> t;
	while (t--) {
		cin >> n;
		ll ans = 0, sum = 0;
		for(int i = 0 ;i < n ;i ++){
			ll cnt = (ll)f[n] * fc[i+1] % mod * fc[n - 1 - i] % mod;
			if((sum += cnt) >= mod) sum -= mod;
			ll t;cin >> t;
			ll pop = t * sum % mod;
			if((ans += pop) >= mod) ans -= mod;
			ll opo = (ll)f[n] * fc[i] % mod * fc[n - i] % mod;
			if((sum -= opo) < 0 ) sum += mod;
		}
		cout << ans << endl;
	}
	return 0;
}

D - Two Sequences

 Gym - 101968D 

题目链接https://codeforces.com/gym/101968/problem/D

#include <bits/stdc++.h>
using namespace std;
# define IOS ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
std::map<int, int> mp;
std::map<int, int> mp2;
int main(int argc, char const *argv[])
{
	IOS;
	int t;
	cin>> t;
	while(t--){
		mp.clear();
		mp2.clear();
		int n , k ;
		cin >>  n >>  k;
		for(int i = 1 ;i <= n ; i++){
			int x ;
			cin >> x;
			mp[x]++;
		}
		for(int i = 1; i <= n ; i++){
			int x;
			cin  >> x;
			if(!mp[x]) mp2[x]++;
			else mp[x]--;
			if(!mp[x]) mp.erase(x);
		}
		int sum = 0 , sum2 = 0;
		for(auto au: mp){
			sum += au.second;
		}
		for(auto au : mp2) sum2 += au.second;
		if(mp2.size() == 1 && mp.size() == 1  && sum + sum2 == 2){
			for(auto au : mp2){
				for(auto ae : mp){
					if(abs(au.first - ae.first) <= k) puts("YES");
					else puts("NO");
				}
			}
		}
		else if(mp2.size() + mp.size() == 0) puts("YES");
		else puts("NO");
	}
	return 0;
}

E - Connecting Components

 Gym - 101968E 

题目链接https://codeforces.com/gym/101968/problem/E

F - Mirror

 Gym - 101968F 

题目链接https://codeforces.com/gym/101968/problemF

G - TeddyBearsDay

 Gym - 101968G 

题目链接https://codeforces.com/gym/101968/problem/G

H - Win Strategy

 Gym - 101968H 

题目链接https://codeforces.com/gym/101968/problem/H

/**Today you do things people will not do,
tomorrow you will do things people can not do.**/

#include<bits/stdc++.h>
#define ll long long
#define lson l,m,cnt<<1
#define rson m+1,r,cnt<<1|1
//priority_queue <int,vector<int>,greater<int> > Q;//优先队列递增
//priority_queue<int>Q;//递减
using namespace std;
const int maxn = 1005;
const int mod = 1e9+7;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-6;
int sta[maxn],last[maxn];
int dp[maxn][maxn];
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n,t;
        scanf("%d %d",&n,&t);
        for(int i=1;i<=n;i++)
            scanf("%d%d",&sta[i],&last[i]);
        memset(dp,0,sizeof(dp));
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=t;j++)
                dp[i][j]=dp[i-1][j];
            for(int j=sta[i]+last[i]-1;j<=t;j++)
                dp[i][j]=max(dp[i][j],dp[i-1][j-last[i]]+1);
            for(int j=1;j<=t;j++)
                dp[i][j]=max(dp[i][j],dp[i][j-1]);
        }
        printf("%d\n",dp[n][t]);
    }
}

I - Tours

 Gym - 101968I 

题目链接https://codeforces.com/gym/101968/problem/I

J - Restricted Vertex Cover

 Gym - 101968J 

题目链接https://codeforces.com/gym/101968/problem/J

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值