Codeforces Round #680 (Div. 2, based on Moscow Team Olympiad)A~D

A

#include<bits/stdc++.h>
#define debug(x) cout<<#x<<" is "<<x<<endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define DBG 0
const int N = 1e5 + 5;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LLINF = (1LL<<60);
using namespace std;
const int mod = 998244353;
ll fast_pow(ll a,ll b){
	ll ans = 1;
	while(b){
		if(b&1)ans = (ans * a)%mod;
		a = (a * a)%mod;
		b>>=1;
	}
	return (ans%mod);
}
typedef pair<int,int> pii;
int a[N],b[N];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
#if DBG
	freopen("input.txt","r",stdin);
#endif
	int t;
	cin>>t;
	while(t--){
		int n,x;
		cin>>n>>x;
		for(int i = 0;i < n;i++)cin>>a[i];
		for(int i = 0;i < n;i++)cin>>b[i];
		sort(a,a+ n);
		sort(b,b+n,greater<int>());
		bool f = true;
		for(int i = 0; i< n;i++)
			if(a[i] + b[i] > x)f = false;
		printf("%s\n",f?"Yes":"No");
	}
	return 0;
}

B

#include<bits/stdc++.h>
#define debug(x) cout<<#x<<" is "<<x<<endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define DBG 0
const int N = 1e5 + 5;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LLINF = (1LL<<60);
using namespace std;
const int mod = 998244353;
ll fast_pow(ll a,ll b){
	ll ans = 1;
	while(b){
		if(b&1)ans = (ans * a)%mod;
		a = (a * a)%mod;
		b>>=1;
	}
	return (ans%mod);
}
typedef pair<int,int> pii;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
#if DBG
	freopen("input.txt","r",stdin);
#endif
	int t;
	cin>>t;
	while(t--){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		cout<<max(a+b,c+d)<<endl;
	}
	return 0;
}

C

#include<bits/stdc++.h>
#define debug(x) cout<<#x<<" is "<<x<<endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define DBG 0
const int N = 1e5 + 5;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LLINF = (1LL<<60);
using namespace std;
const int mod = 998244353;
ll fast_pow(ll a,ll b){
	ll ans = 1;
	while(b){
		if(b&1)ans = (ans * a);
		a = (a * a);
		b>>=1;
	}
	return ans;
}
typedef pair<int,int> pii;
int prime[N];
vector<int> pri;
void get(){
	for(int i = 2;i <= 100000;i++){
		if(!prime[i]){
			pri.pb(i);
			for(int j = i;j <= 100000;j += i)prime[j]  = 1;
		}
	}
}
//int cnt1[N],cnt2[N];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
#if DBG
	freopen("input.txt","r",stdin);
#endif
	get();
	int t;
	cin>>t;
	while(t--){
		ll p,q;
		cin>>p>>q;
		if(p % q == 0){
			ll min_div= 1e18;
			ll pp = p;
			for(int i = 0;i < pri.size();i++){
				if(q % pri[i] == 0){
					ll cnt1= 0,cnt2= 0;
					while(p % pri[i] == 0){
						p/= pri[i];
						cnt1++;
					}
					while(q % pri[i] ==0){
						q/= pri[i];
						cnt2++;
					}
					min_div = min(min_div,fast_pow(pri[i],cnt1 - cnt2 + 1));
				}
			}
			if(q != 1){
				ll cnt = 0;
				while(p % q == 0)cnt++,p/=q;
				min_div = min(min_div,fast_pow(q,cnt));
			}
			cout<<pp/min_div<<endl;
		}else
			cout<<p<<endl;
	}
	return 0;
}

D.考虑将2n个元素中较小的一半归为集合L,较大的一半归为集合R。
考虑某种划分(p,q),对于任意位置i, p_i,q_i 不可能都属于L。
假定都属于 L, 则 p_1p_i属于L,q_iq_n 属于L,则L有n+1个元素,矛盾。
同理p_i,q_i 不可能都属于R,则p_i,q_i一个属于L,一个属于R。
任意划分(p,q)对答案的贡献都是sum®-sum(L)

#include<bits/stdc++.h>
#define debug(x) cout<<#x<<" is "<<x<<endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define DBG 0
const int N = 3e5 + 5;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LLINF = (1LL<<60);
using namespace std;
const int mod = 998244353;
ll fast_pow(ll a,ll b){
	ll ans = 1;
	while(b){
		if(b&1)ans = (ans * a)%mod;
		a = (a * a)%mod;
		b>>=1;
	}
	return (ans%mod);
}
typedef pair<int,int> pii;
ll a[N],b[N];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
#if DBG
	freopen("input.txt","r",stdin);
#endif
	int n;
	cin>>n;
	for(int i = 1;i <= n;i++)
		cin>>a[i];
	for(int i = 1;i <= n;i++)
		cin>>b[i];
	sort(a + 1,a + 1 + n);
	sort(b + 1,b + 1 + n,greater<int>());
	ll ans = 0;
	for(int i = 1;i <= n;i++)
		ans += abs(a[i] - b[i]),ans %= mod;
	for(int i = 2 * n;i > n;i--)
		ans = (ans * i)%mod;
	for(int i = n;i >= 1;i--)
		ans = (ans * fast_pow(i,mod - 2))%mod;
	cout<<ans<<endl;
	return 0;
}

E
----------------待补-------------------

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值