目录
A - Tree Game
题目链接https://codeforces.com/gym/101968/problem/A
B - Rectangles
题目链接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
题目链接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
题目链接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
题目链接https://codeforces.com/gym/101968/problem/E
F - Mirror
题目链接https://codeforces.com/gym/101968/problemF
G - TeddyBearsDay
题目链接https://codeforces.com/gym/101968/problem/G
H - Win Strategy
题目链接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
题目链接https://codeforces.com/gym/101968/problem/I