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为还需要的蜡烛数, ...
随机推荐
- 2022-3-11内部群每日三题-清辉PMP
1.供应商通知项目经理可能延迟交付一个模块.项目经理应该怎么做? A.立即通知相关方. B.通过增加额外的天数来修改项目管理计划,并记录它们对项目时间的影响. C.审查风险管理计划以评估风险,然后通知 ...
- 无法启动iis服务器
网上的大多数教程都千篇一律,增加我寻找解决方法的难度 ,在我边气边找的努力下终于找到了解决办法. 不过还是建议先去看其他的教程,其他的不行的话再来看这个 因为工作进程未能正确初始化,因而无法启动.返回 ...
- Jenkins+Appium+Pytest+Allure集成
前提: 已经部署好了Jenkins环境,包括工具配置等 我的环境: Jenkins服务由安装在虚拟机上的Docker启动 Appium相关运行环境安装在虚拟机所在的主机上windows 方式:在Jen ...
- Linux基础第十章:系统安全及应用
目录 一.账户安全措施 1.账户管理 2.锁定配置文件 3.清除历史记录 二.sudo 1.sudo概念及优点 2.使用sudo 3.sudo实操演示 4.设置sudo别名 5.sudo特别注意 一. ...
- bigdecimal 比较大小、bigdecimal 数学运算、bigdecimal 精度
创建 BigDecimal 建议使用 public BigDecimal(String val),使用 number 参数可能会有精度问题 设置精度 setScale(3, BigDecimal.RO ...
- linux下nginx的(启动、重启、关闭)
1. 首先利用配置文件启动nginx. 命令: nginx -c /usr/local/nginx/conf/nginx.conf 重启服务: service nginx restart 2. 快速停 ...
- bootstrap-select使用、relation-graph使用
bootstrap-select 这里要实现的是带有搜索功能的select框, bootstrap 官网没有可以直接拿来用的.如下是官网给出的解释,带搜索功能的select需要自定义. 在网上找到了有 ...
- shell语法2-默认变量、数组
一:文件参数变量 1.在执行shell脚本时,可以向脚本传递参数.$1是第一个参数,$2是第二个参数,以此类推.特殊的,$0是文件名(包含路径) #! /bin/bashecho "文件名: ...
- pycharm开发工具的介绍和使用
pycharm开发工具的介绍和使用 PyCharm是常用的python开发工具之一,分为社区版和专业版,社区版只有基础的python环境,专业版的功能会多很多
- Django练习过程中的错误即解决方案
问题1 这个问题是当我们跟着书上做完后,没有按照规定输入 python manage.py makemigrations learning_logs 然后输入: python manage.py mi ...