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题解的更多相关文章

  1. Codeforces Round #460 (Div. 2) ABCDE题解

    原文链接http://www.cnblogs.com/zhouzhendong/p/8397685.html 2018-02-01 $A$ 题意概括 你要买$m$斤水果,现在有$n$个超市让你选择. ...

  2. Codeforces Round #546 (Div. 2) ABCDE 题解

    1136A: 题意:一本书有n个章节,每个章节的分别在li到ri页,小明读完书后将书折在第k页,问还有多少章节没有读 题解:控制k在li~ri的范围内后输出n-i即可 #include <set ...

  3. Codeforces Round #353 (Div. 2) ABCDE 题解 python

    Problems     # Name     A Infinite Sequence standard input/output 1 s, 256 MB    x3509 B Restoring P ...

  4. Codeforces Round #261 (Div. 2)[ABCDE]

    Codeforces Round #261 (Div. 2)[ABCDE] ACM 题目地址:Codeforces Round #261 (Div. 2) A - Pashmak and Garden ...

  5. # Codeforces Round #529(Div.3)个人题解

    Codeforces Round #529(Div.3)个人题解 前言: 闲来无事补了前天的cf,想着最近刷题有点点怠惰,就直接一场cf一场cf的刷算了,以后的题解也都会以每场的形式写出来 A. Re ...

  6. Codeforces Round #557 (Div. 1) 简要题解

    Codeforces Round #557 (Div. 1) 简要题解 codeforces A. Hide and Seek 枚举起始位置\(a\),如果\(a\)未在序列中出现,则对答案有\(2\ ...

  7. Codeforces Round #540 (Div. 3) 部分题解

    Codeforces Round #540 (Div. 3) 题目链接:https://codeforces.com/contest/1118 题目太多啦,解释题意都花很多时间...还有事情要做,就选 ...

  8. Codeforces Round #538 (Div. 2) (A-E题解)

    Codeforces Round #538 (Div. 2) 题目链接:https://codeforces.com/contest/1114 A. Got Any Grapes? 题意: 有三个人, ...

  9. Codeforces Round #531 (Div. 3) ABCDEF题解

    Codeforces Round #531 (Div. 3) 题目总链接:https://codeforces.com/contest/1102 A. Integer Sequence Dividin ...

  10. Codeforces Round #527 (Div. 3) ABCDEF题解

    Codeforces Round #527 (Div. 3) 题解 题目总链接:https://codeforces.com/contest/1092 A. Uniform String 题意: 输入 ...

随机推荐

  1. jmeter使用json断言校验返回结果

    jmeter断言有好几种方式,本案讲json断言 http请求返回数据的格式有json格式,如下图,比如需要验证"ShipperRealName"参数的值 步骤如下: 第一步,选中 ...

  2. 20241106,LeetCode 每日一题,用 Go 实现整数回文数判断

    题目 给你一个整数 x ,如果 x 是一个回文整数,返回 true :否则,返回 false . 回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数.* 例如,121 是回文,而 123 不 ...

  3. 等保2.0>Windows下实现MySQL数据库自动备份

    说明: MySQL数据库安装目录:C:\Program Files\mysql-5.7.37-winx64\mysql-5.7.37-winx64 MySQL数据库存放目录:C:\Program Fi ...

  4. Beyond Compare 4 便携版 添加右键菜单

    Beyond Compare 4 便携版 添加右键菜单 一.从安装版中复制所需的 dll 文件 便携版默认不带 Shell Extension 所需的 dll 文件,可以从安装版复制: 例如,从 &q ...

  5. 操作系统综合题之“银行家算法,计算各资源总数和Need还需要数量和解释什么是安全状态以及银行家进阶题(额外提出资源请求计算是否满足)”

    一.问题:某系统在某时刻的进程和资源状态如下表所示: 进程 Allocation(已分配资源数) (A B C D) Max(最大需要资源数) (A B C D) Avaliable(可用资源数) ( ...

  6. 如何清理误提交到git的历史大文件?

    前言 哈喽!好久不见~ 最近在思考转型的事情,好久没有更新文章了 不过看到我之前开发的视频剪辑工具 Clipify 收获了不少 star ,让我想起之前画的饼似乎才实现了一点点,所以利用了周末的空闲时 ...

  7. 手把手教你实现MVVM架构

    .markdown-body { color: rgba(89, 89, 89, 1); font-size: 15px; font-family: -apple-system, system-ui, ...

  8. 关于I/O与并发

    前言 由于笔者在之前发布的一文玩转NGINX中提到过I/O复用模型,在此另起一篇文章简述相关技术. 什么是I/O I/O输入/输出(Input/Output),分为IO设备和IO接口两个部分. 在PO ...

  9. linux中部署自己的系统内核

    1.计算机是如何将系统起起来的?-- PC机的引导流程 PC机BIOS固件是固化在PC机主板上的ROM芯片中,断电也能保存,PC机上电后的第一条指令就是在BIOS固件中,它负责检测和初始化CPU.内存 ...

  10. 创建字符串对象的六种方法(java)

    package javaBasic; public class StringConstruction { public static void main(String[] args) { String ...