Codeforces Round #693 (Div. 3) ABCDE题解
A. Cards for Friends
思路:折纸游戏,看长宽能各折多少次,就是2的几次方,相乘即可。
view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };
int main()
{
int kase;
cin>>kase;
while(kase--)
{
ll w = read(), h = read(), n = read();
ll cnt1 = 0, cnt2 = 0;
while(w%2==0&&w)w/=2, cnt1++;
while(h%2==0&&h) h/=2, cnt2++;
if((1LL<<cnt1)*(1LL<<cnt2)>=n) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}
B. Fair Division
思路:首先看1的个数,若1的个数为奇数肯定不能均分。
若1的个数是偶数,就继续看2的个数,如果2这时候也是偶数就肯定能均分完。但是如果2的数量是奇数个,说明有个人要多拿一个2,所以看均分好的1够不够每个人都大于等于1个,这个时候2多拿的那个人少拿一个1就行了。
view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };
int main()
{
int kase;
cin>>kase;
while(kase--)
{
ll n = read();
ll cnt1 = 0, cnt2 = 0;
rep(i,1,n)
{
ll x = read();
if(x==1) cnt1++;
else cnt2++;
}
if(cnt1&1) cout<<"NO"<<endl;
else
{
if(cnt2&1)
{
if(cnt1>=2) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
else cout<<"YES"<<endl;
}
}
return 0;
}
C. Long Jumps
思路:每次到的地方i+a[i]处的贡献可以提前知道,类似dp。从后到前遍历,d[i] = d[i+a[i]] + a[i]。
view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 2e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };
ll a[maxn];
ll d[maxn];
int main()
{
int kase;
cin>>kase;
while(kase--)
{
ll n = read();
rep(i,1,n) a[i] = read();
d[n] = a[n];
ll ma = d[n];
per(i,n-1,1)
{
ll to = i + a[i];
if(to<=n) d[i] = d[to] + a[i];
else d[i] = a[i];
ma = max(ma,d[i]);
}
cout<<ma<<endl;
}
return 0;
}
D. Even-Odd Game
思路:考虑回合制。首先贪心,如果我有大的肯定会先拿大的,把各自奇偶数分开排序。
然后如果是Alice回合(拿偶数round),我可以自己拿偶数加分或者拿掉对面最大的(奇数)让对手难受。怎么判断拿哪个呢?其实就看各自的贡献,如果我当前最大比对方的最大要小,我就拿走对方的,这样我就算损失也可以尽可能小。反之就赶紧把自己大的这个拿走,不然对方会用同样招数来恶心你。
对于Bob也是如此。
view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 2e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };
ll odd[maxn];
ll even[maxn];
int main()
{
int kase;
cin>>kase;
while(kase--)
{
ll n = read();
int p1 = 0;
int p2 = 0;
rep(i,1,n)
{
ll x = read();
if(x&1) odd[++p1] = x;
else even[++p2] = x;
}
sort(odd+1,odd+1+p1);
sort(even+1,even+1+p2);
ll a = 0;
ll b = 0;
int cnt = 1;
while(p1>=1||p2>=1)
{
if(cnt&1)
{
if(p1>=1&&odd[p1]>even[p2]) p1--;
else a += even[p2--];
}
else
{
if(p2>=1&&even[p2]>odd[p1]) p2--;
else b += odd[p1--];
}
cnt++;
}
if(a>b) cout<<"Alice"<<endl;
else if(a<b) cout<<"Bob"<<endl;
else cout<<"Tie"<<endl;
}
return 0;
}
E. Correct Placement
思路:注意题目输出的要求,他说随便找一个能放到i前面的就好了,本身就在i前面但满足题意的也可以当做一个解。
那我们先对原二元组按照w排序,现在w是从小到大了。然后我们只用顺序遍历一遍,因为前面的w肯定比当前的小,遍历的时候记录最小的h及其原下标即可。如果前面有最小h小于当前h的就直接用那个记录的原下标。
但是因为有重复的w存在,所以会出现下面这种情况:
1 5
2 3
2 6
2 7
如果在i=2的时候改变原下标(变成id=2),那么后面两个w=2的都会找不到解。所以遇到后面还有w一样的要先判断完再更新。
view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 2e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };
typedef struct Pos
{
ll w;
ll h;
ll id;
bool operator < (const Pos &a) const
{
if(w!=a.w)
return w<a.w;
return h<a.h;
}
}P;
P a[maxn];
ll Ans[maxn];
int main()
{
int kase;
cin>>kase;
while(kase--)
{
ll n = read();
rep(i,1,n)
{
ll w = read(), h = read();
if(w>h) swap(w,h);
a[i].w = w;
a[i].h = h;
a[i].id = i;
}
sort(a+1,a+1+n);
ll mih = inf;
ll miw = inf;
ll cur = 0;
rep(i,1,n)
{
if(a[i].h>mih&&a[i].w>miw) Ans[a[i].id] = cur;
else
{
int p = i+1;
Ans[a[i].id] = -1;
while(p<=n&&a[p].w==a[i].w)
{
if(a[p].w>miw&&a[p].h>mih) Ans[a[p].id] = cur;
else Ans[a[p].id] = -1;
p++;
}
cur = a[i].id;
mih = a[i].h;
miw = a[i].w;
i = p-1;
}
}
rep(i,1,n) cout<<Ans[i]<<' '; cout<<endl;
}
return 0;
}
Codeforces Round #693 (Div. 3) ABCDE题解的更多相关文章
- Codeforces Round #460 (Div. 2) ABCDE题解
原文链接http://www.cnblogs.com/zhouzhendong/p/8397685.html 2018-02-01 $A$ 题意概括 你要买$m$斤水果,现在有$n$个超市让你选择. ...
- Codeforces Round #546 (Div. 2) ABCDE 题解
1136A: 题意:一本书有n个章节,每个章节的分别在li到ri页,小明读完书后将书折在第k页,问还有多少章节没有读 题解:控制k在li~ri的范围内后输出n-i即可 #include <set ...
- Codeforces Round #353 (Div. 2) ABCDE 题解 python
Problems # Name A Infinite Sequence standard input/output 1 s, 256 MB x3509 B Restoring P ...
- Codeforces Round #261 (Div. 2)[ABCDE]
Codeforces Round #261 (Div. 2)[ABCDE] ACM 题目地址:Codeforces Round #261 (Div. 2) A - Pashmak and Garden ...
- # Codeforces Round #529(Div.3)个人题解
Codeforces Round #529(Div.3)个人题解 前言: 闲来无事补了前天的cf,想着最近刷题有点点怠惰,就直接一场cf一场cf的刷算了,以后的题解也都会以每场的形式写出来 A. Re ...
- Codeforces Round #557 (Div. 1) 简要题解
Codeforces Round #557 (Div. 1) 简要题解 codeforces A. Hide and Seek 枚举起始位置\(a\),如果\(a\)未在序列中出现,则对答案有\(2\ ...
- Codeforces Round #540 (Div. 3) 部分题解
Codeforces Round #540 (Div. 3) 题目链接:https://codeforces.com/contest/1118 题目太多啦,解释题意都花很多时间...还有事情要做,就选 ...
- Codeforces Round #538 (Div. 2) (A-E题解)
Codeforces Round #538 (Div. 2) 题目链接:https://codeforces.com/contest/1114 A. Got Any Grapes? 题意: 有三个人, ...
- Codeforces Round #531 (Div. 3) ABCDEF题解
Codeforces Round #531 (Div. 3) 题目总链接:https://codeforces.com/contest/1102 A. Integer Sequence Dividin ...
- Codeforces Round #527 (Div. 3) ABCDEF题解
Codeforces Round #527 (Div. 3) 题解 题目总链接:https://codeforces.com/contest/1092 A. Uniform String 题意: 输入 ...
随机推荐
- 关于class类的知识点记录
下方代码,初始化test的一系列参数和对应的值 class SendMsg(object): def __init__(test): test.name = {'Adele baby','beckha ...
- git rebae -i
这个命令大体作用就是对本地的commit进行修改,适用于以下情况: 本地历史排查修改 code review后,打回修改 详解 pick,只是意味着包括提交.重新进行命令时,重新安排pick命令的顺序 ...
- DeepSeek在IT运维中的实战应用与价值创新
DeepSeek在IT运维中的实战应用与价值创新可以从以下几个方面展开分析,结合技术能力.场景适配与商业价值,提供系统化的视角: 一.核心应用场景与实战价值 1. **故障预测与主动防御** - ** ...
- 【记录】BASE64|解决JS和C++中文传输乱码,内含两种语言的Base64编码解码的代码
JS 解决方法来源于知乎新码笔记的文章 function b64Encode(str) { return btoa(unescape(encodeURIComponent(str))); } func ...
- 操作系统综合题之“短进程优先调度算法(Shortest-Process-First,SPF)和非抢占式优先权调度算法(Priority-Scheduling Lgorithm)的进程执行顺序并计算周转时间以及平均周转时间【分开计算题】”
一.问题: 1.当系统采用短进程优先调度算法时,试写出进程的执行顺序,并计算各个进程的周转时间以及平均周转时间 2.当系统采用优先权调度算法时,试写出进程的执行顺序,并计算各个进程的周转时间以及平均周 ...
- 实战研究:提升Web应用的安全性
@charset "UTF-8"; .markdown-body { line-height: 1.75; font-weight: 400; font-size: 15px; o ...
- QtWidget项目-仿腾讯QQ音乐
本博客主要介绍本人写的个人项目 - QtWidget5 仿腾讯QQ音乐项目. 效果演示 项目详情 源码 Gitee地址:https://gitee.com/run-little-peach/my-qq ...
- 解决Git异常 Access denied your account has 2FA enabled
摘要:解决Git双因子身份验证问题. 问题背景 在使用账号和密码的方式拉取公司GitLab代码时,遇到了以下错误提示问题: remote: HTTP Basic: Access denied. T ...
- Windows加域后通过注册表取消壁纸锁定更换壁纸
打开注册表: 开始--运行--regedit (快捷键Win+R) 然后找到HKEY_CURRENT_USER ==> Software ==> Microsoft ==> Wind ...
- 题解:P6880 [JOI 2020 Final] オリンピックバス
一个比较重要的性质:反转的边要在最短路上才会有贡献. 我们可以先跑一遍最短路,记录下整颗最短路树,然后暴力的对每一条边进行判断,反转. 我们建正反图各两个,分别以 \(1\),\(n\) 为起点.\( ...