Codeforces Round #762 (Div. 3), CDE
(C) Wrong Addition
题意
定义一种计算方式, 对于a+b=c, 给出a和c, 求b

题解
因为求法是从个位求得, 先求出来的最后输出, 符合栈的存储方式, 所以b用栈来存
每次拿c的最后一位(若小于a最后一位, 则取后两位)减去a的最后一位, 存入b的栈
需要注意的是,: 1.若c已经没了, 但是a还有, 则无解
2. 若c中出现00则无解(下面代码中, 以c后两位<a最后一位判断的)
3. 减去后有两位数, 因为每次求出来的只能是b的一个数字
AC代码
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N = 1e6+10;
int a[N];
int main()
{
int t;
cin >> t;
while(t --)
{
string s, a;
bool f = 1;
stack<int> c;
cin >> a >>s;
for(int i = a.size()-1, j = s.size()-1; j >= 0; i --, j --)
{ int aa = i>=0?a[i]-'0':0;
int ss = s[j]-'0';
if(ss<aa)
{
if(j==0)
{f=0; break;}//这里是防止下面越界
ss =( s[--j]-'0')*10 + ss;
if(ss<aa){f=0; break;}
}
if(ss-aa>=10){f=0; break;}//减去后有两位数
c.push(ss-aa);
if(j==0&&i>j){f=0; break;}
}
if(!f)puts("-1");
else
{
LL x = 0;
while(c.size())
{
x=(LL)c.top()+x*(LL)10;
c.pop();
}
cout << x<<'\n';
} } return 0;
}
D. New Year's Problem
题意
输入顺序是先m后n
张三有 n 个朋友,要在 m 个商店中选一些商店给他的朋友买礼物(最多选n − 1个商店),要求每个朋友都要收到礼物。
要求最大化 min(每个朋友获得的礼物价值)
题解--二分
对于每个商店--行 : 至少有一个店有两个 礼物>=所枚举的mid, 且最后礼物>=所枚举的mid的礼物总数>=n
对于每个朋友--列 : 每个朋友至少有一个礼物
符合以上条件check函数就完成了
本题学到了对于n*m<=2e5存储的刁钻方法
vector<vector<int> > a(m, vector<int>(n));//定义
bool check(int x, vector<vector<int>> &a)//传入地址
AC代码
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N = 2e5+10;
int m, n; bool check(int x, vector<vector<int>> &a)
{
int ff=0;int f = 0;
for(int i = 0; i < m; i ++)
{
int b=0;
for(int j = 0; j < n; j ++)
{
if(a[i][j]>=x)f ++, b++;
}
if(b>1)ff=1;
}
if(!ff || f<n)return 0; for(int j = 0; j < n; j ++)
{
int f = 0;
for(int i = 0; i < m; i ++)
{
if(a[i][j]>=x)f ++;
}
if(!f)return 0;
}
return 1;
} int main()
{
int t;
cin >> t;
while(t --)
{ cin >> m >> n;
vector<vector<int> > a(m, vector<int>(n));
for(int i = 0; i < m; i ++)
for(int j = 0; j <n; j ++)
cin>> a[i][j]; int l = 0, r = 1e9;
while(l < r)
{
int mid = l+r+1>>1;
if(check(mid, a))l = mid;
else r = mid-1;
}
cout <<l<<endl;
} return 0;
}
E. MEX and Increments(比D简单)
题意
给一串数, 求出当mex=0~n是需要的最小操作数
每一操作可以选择一个数+1, 注: mex=数组中未包含的最小非负整数
题解
对于mex=i时, 输出=数组内i的个数+x
x=补齐1~i-1所需的操作数
多余的数放入优先队列就行了, 每次出来最大的数, 这样差值最小
本题又复习了优先队列好耶!
priority_queue<int, vector<int>> heap;//大到小
priority_queue<int, vector<int>, greater<int>> heap;//小到大
AC代码
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5+10;
int a[N], b[N], c[N]; int main(){
int t;
cin >> t;
while(t --)
{
int n;
cin >> n;
for(int i = 0;i <= n ; i++) b[i]=0;
for(int i = 0;i < n ; i++) cin >> a[i], b[a[i]]++;
sort(a,a+n);
priority_queue<int, vector<int>> heap; bool f = 0;
LL x=0, y=0;
for(int i = 0; i <= n; i ++)
{
if(i && y<i)
{
f = 1;
for(int j = i; j <= n; j ++)cout <<"-1 ";
break;
}
else
{ if(a[i]<=i)
y++;
if(i && b[i-1]==0)
{
int t = heap.top();
heap.pop();
x += i-1-t;
}
if(b[i]>1)
for(int j = 2; j <= b[i]; j ++)heap.push(i);//多余的数进队
cout << x+b[i]<<' ';
}
}
cout << endl;
}
return 0;
}
Codeforces Round #762 (Div. 3), CDE的更多相关文章
- Codeforces Round #542(Div. 2) CDE 思维场
C https://codeforces.com/contest/1130/problem/C 题意 给你一个\(n*m\)(n,m<=50)的矩阵,每个格子代表海或者陆地,给出在陆地上的起点终 ...
- Codeforces Round #415 (Div. 1) (CDE)
1. CF 809C Find a car 大意: 给定一个$1e9\times 1e9$的矩阵$a$, $a_{i,j}$为它正上方和正左方未出现过的最小数, 每个询问求一个矩形内的和. 可以发现$ ...
- 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 ...
随机推荐
- Nginx高并发实现原理以及常用的优化手段
Nginx 是如何实现高并发的? 异步,非阻塞,使用了epoll 和大量的底层代码优化. 如果一个server采用一个进程负责一个request的方式,那么进程数就是并发数.正常情况下,会有很多进程一 ...
- Mybatis中Log4j日志的使用
参考资料: (1). 百度百科:https://baike.baidu.com/item/log4j/480673?fr=aladdin (2). B站狂神的视频:https://www.bilibi ...
- JS如何通过月份,计算月份相差几个月
1 var tr = ''; 2 <script> 3 $.each(data, function (index, item) { 4 let startTime = new Date(i ...
- 抖音网页版高清视频抓取教程selenium
废话不多说,直接上代码 from selenium import webdriver from selenium.webdriver import ChromeOptions import time ...
- 使用 RabbitMQ 有什么好处?
(1)服务间高度解耦 (2)异步通信性能高 (3)流量削峰
- String、StringBuiler、StringBuffer的区别
一.三者的区别概述 1.可变与不可变:String底层使用final修饰的字符数组来存储字符串,它属于不可变类,对String对象的任何改变操作都不会改变原对象,而是生成一个新对象.StringBui ...
- 学习Kvm(六)
五,管理虚拟存储 5.1 虚拟磁盘概述 5.1.1 虚拟化项目中存储的注意事项 [x] 存储的性能几乎总是虚拟化的瓶颈 [x] 通过多个硬盘驱动以分布磁盘I/O来实现存储解决方案 [x] 考虑部署集中 ...
- Redis++:Redis做分布式锁真的靠谱吗
Redis做分布式锁真的靠谱吗 Redis的分布式锁可以通过Lua进行实现,通过setnx和expire命令连用的方式 || 也可以使用高版本的方法同时设置失效时间,但是假如在以下情况下,就会造成无锁 ...
- 一次关于关系抽取(RE)综述调研的交流心得
本文来自于一次交流的的记录,{}内的为个人体会. 基本概念 实事知识:实体-关系-实体的三元组.比如, 知识图谱:大量实时知识组织在一起,可以构建成知识图谱. 关系抽取:由于文本中蕴含大量事实知识,需 ...
- js 获取和设置css3 属性值的实现方法
众多周知 CSS3 增加了很多属性,在读写的时候就没有原先那么方便了. 如:<div style="left:100px"></div> 只考虑行间样式的话 ...