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

  1. 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 ...

  2. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  3. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  4. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  5. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  6. 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 ...

  7. 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 ...

  8. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

  9. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

  10. 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts

    题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...

随机推荐

  1. Linux一键单机部署和集群部署

    整个部署脚本只用执行sh即可,有需要可以联系我. 一.部署类型 可参考:常见的部署类型(停机部署.蓝绿部署.滚动部署.灰度部署.AB测试等) 二.一键单机部署Docker服务 三.一键单机部署原生服务 ...

  2. node.js请求css、js静态资源页面不生效

    产生原因:文件响应头内容类型错误 解决方案:设置对应的响应头内容类型 const http = require('http'); const fs = require('fs'); const pat ...

  3. UR #3 核聚变反应强度( gcd )

    tags: -分解质因数 , gcd 题目大意 给定\(n\)个数,求\(a_1\)与\(a_i\)次小公约数 分析 易知次小公约数是\(\gcd\)的因数,于是用\(\gcd\)除去它的最小质因子即 ...

  4. c语言中的原子操作

    参考文章:https://blog.csdn.net/yikai2009/article/details/8650221 1. 原子操作:原子操作指的是在执行过程中不会被别的代码所中断的操作..分为 ...

  5. 修改mysql 一张表中某列字段值

    UPDATE  表名 SET  字段名 = replace(字段名,'原来值','修改值'): 例: UPDATE pd_purchase SET type_status =replace(type_ ...

  6. react文件分片上传

    参考文档: https://blog.csdn.net/weixin_39887846/article/details/113492372 https://juejin.cn/post/6844904 ...

  7. 微服务注册到Nacos上的Ip错误,是内网ip不是公网ip

    spring.cloud.nacos.discovery.ip = 本机公网IP spring.cloud.nacos.discovery.port = 服务端口

  8. Android studio 使用Internet传递信息

    使用Intent在Activity之间传递信息1.首先创建一个新的Activity,在activity_main.xml中设计页面,将android.support.constraint.Constr ...

  9. Unity学习笔记——坐标转换(3)

    通过Transform.Translate移动物体         6个重载:         public void Translate(float x, float y, float z, [De ...

  10. 量化交易-可视化展示(grafana)

    先上图 简单的实现了一下,效果还好,可玩性强 大概部署mysql+grafana step 1: 服务器:阿里云,ucloud啥的随意,配置也不需要什么,我的是阿里云1核1GB,足以 我用的ubunt ...