Codeforces Round 857 (Div. 2) A-D
Codeforces Round 857 (Div. 2)
A. Likes
求每回合最大的数列:先全使用正数,每个正数对ans++,再全使用负数,每个负数对ans--
求每回合最小的数列:方法1(模拟):若有负数未被使用且目前点赞数>0,则使用负数对ans--;否则使用正数
方法2(绝对值排序):按照绝对值从小到大排序,依次按正数,负数相应对ans操作
void solve(){
int n=read();
int l=0,d=0;
for(int i=1;i<=n;i++){
int x=read();
if(x>0) l++;
else d++;
}
int l1=l,dd=d,ans=0;
while(l1--){
ans++;
cout<<ans<<" ";
}while(dd--){
ans--;
cout<<ans<<" ";
}
cout<<endl;
ans=0;
while(l||d){
if(ans&&d){
d--;
ans--;
}else {
l--;
ans++;
}
cout<<ans<<" ";
}
cout<<endl;
}
B. Settlement of Guinea Pigs
按照题意有推论:(1) 未确认性别的小豚鼠只能一个人一个房子 记为L
(2) 已确认性别的小豚鼠若有n只,则这n只需(n+2)/2个房子 记为D
所以我们可以模拟过程,记录过程中的 ans=max(D+L,ans)
void solve(){
int n=read();
int l=0,d=0,need=0,ans=0;
for(int i=1;i<=n;i++){
int x=read();
if(x==1) l++;
else {
if(d==0)need=max(need,l);
else need=max(need,(d+2)/2+l);
d+=l;
l=0;
}
if(need>ans){
ans=need;
}
}
if(l){
if(d==0)need=max(need,l);
else need=max(need,(d+2)/2+l);
d+=l;
l=0;
if(need>ans){
ans=need;
}
}
cout<<ans<<endl;
}
C. The Very Beautiful Blanket
根据题目样例,需要构造每四个数的矩阵异或和为0,且矩阵内每个数不同
赛后看了jiangly的代码,发现好简单 (马后炮是这样的)
void solve(){
int n=read(),m=read();
cout<<n*m<<endl;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cout<<(i<<10)+j<<" \n"[j == m - 1];
}
}
}
D. Buying gifts
贪心题 依然学习jiangly的代码 (一开始没看明白,后面把mx的数输出又看了半天 发现妙啊)
先把所有店的两种物品都放在一起排序,同时记录val和给谁的,然后用bad记录目前未经历的店家数量
若bad为0 说明所有店家都经历过了,因为经过排序,目前每个人手上都是必须拥有的最小价值,同时利用mx迭代最大和第二大的val,再利用2*2的格子对可能的格子进行比较,注意排除同一个店里的情况
void solve(){
int n=read();
vector<PII>a(2*n);
for(int i=0;i<n;i++){
int x=read(),y=read();
a[2*i]={x,2*i};
a[2*i+1]={y,2*i+1};
}
sort(a.begin(),a.end());
PII mx[2][2];
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
mx[i][j]={-1,-1};
}
}
vector<bool>vis(n);
int bad=n,ans=1e9;
for(auto [v,t]:a){
int u=t%2;
mx[u][1]=mx[u][0];
mx[u][0]={v,t};
bad-=!vis[t/2];
vis[t/2]=true;
for(int i=0;i<2;i++){
if(bad==0&&mx[!u][i].second!=-1&&mx[!u][i].second!=(t^1)){
ans=min(ans,v-mx[!u][i].first);
}
}
}
cout<<ans<<endl;
}
Codeforces Round 857 (Div. 2) A-D的更多相关文章
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- Codeforces Round #268 (Div. 2) ABCD
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
- 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts
题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...
随机推荐
- pg copy用法
postgresql copy用法1,导出表数据1)导出test表数据到txt copy test to '/home/jinli/test.txt'; 2)导出test表数据到csv copy te ...
- 【2020NOI.AC省选模拟#5】C. 光滑序列
题目链接 原题解: 光滑的序列一定有长度为$K$的循环节. 使用动态规划,设$F(i,j)$为使前$i$个整数的和为$j$的最小修改次数. 记$cost(i,v)$为令$A_i,A_{i+K},A_{ ...
- Pnetlab中锐捷镜像反复重启或telnet无法键入内容
PNETLab 版本: 5.2.7 或 5.3.3等 锐捷镜像版本: V1.03 故障详情: 基于前文的系统环境和锐捷镜像.替换后的yml文件,更新PnetLAB版本到5.3.3后,设备循环重启,无法 ...
- Vue RSA加密
1. 安装jsencrypt npm install jsencrypt 2. 引入jsencrypt // 全局引入 import JSEncrypt from "jsencrypt&qu ...
- react实现转盘动画
转盘动画方法如下: /** * 点击转动转盘 */ const turnCircle = () => { let runDeg = +(Math.random() * 360).toFixed( ...
- mysql datetime和timestamp区别
datetime: 保存格式为YYYYMMDDHHMMSS的整数,与时区无关,存入什么值就是什么值,不会根据当前时区进行转换.mysql5.6.4中可以存储小数片段,最多小数点后6位,在mysql5. ...
- js 导出excle文件(多页)
--前提:页面生成相应的表格数据 例如: <table id="a"> <tr> <th></th> </tr> ...
- visio画图去掉背景框和latex导入pdf边框问题
vision背景边框线问题 pdf导入latex边框问题 结果
- IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number
print('Epoch[{}/{}], loss:{:.6f}'.format(epoch+1,num_epoch,loss.data[0])) 将loss.data[0] 改为loss.item( ...
- 使用navicat连接本地数据库时,出现错误1251错误
在安装完MySQL的时候,我们现在一般都使用Navicat来连接数据库,可惜出现下面的错误:1251-Client does not support authentication protocol r ...