(C) Wrong Addition

Problem - C - Codeforces

题意

定义一种计算方式, 对于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

Problem - D - Codeforces

题意

输入顺序是先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简单)

Problem - E - Codeforces

题意

给一串数, 求出当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的更多相关文章

  1. Codeforces Round #542(Div. 2) CDE 思维场

    C https://codeforces.com/contest/1130/problem/C 题意 给你一个\(n*m\)(n,m<=50)的矩阵,每个格子代表海或者陆地,给出在陆地上的起点终 ...

  2. Codeforces Round #415 (Div. 1) (CDE)

    1. CF 809C Find a car 大意: 给定一个$1e9\times 1e9$的矩阵$a$, $a_{i,j}$为它正上方和正左方未出现过的最小数, 每个询问求一个矩形内的和. 可以发现$ ...

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

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

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

  5. Codeforces Round #368 (Div. 2)

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

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

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

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

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

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

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

随机推荐

  1. Flask 之 WebSocket

    http:是一个协议 规定:数据传输格式 -/r/n/r/n 一次的请求,一次的响应,断开了 短链接 无状态 服务器收到的请求,做出的响应给客户端 客户端主动向服务器发起请求 基于socket sen ...

  2. 你应该知道的Redis过期键和过期策略

    今天,我和大家分享一篇关于 Redis 有关过期键的内容,主要有四个内容: 如何设置过期键 如何取消设置的过期时间 过期键的过期策略是怎样的 RDB.AOF 和复制对过期键的处理又是怎样的 设置键的生 ...

  3. 通过webgoat-xxe、jwt学习Java代码审计

    WebGoat-JWT JWT Tokens 01 概念 本课程将介绍如何使用JSON Web Token(JWT)进行身份验证,以及在使用JWT时需要注意的常见陷阱. 目标 教授如何安全地实现令牌的 ...

  4. [FromBody]List<string> 用PostMan如何请求

    在MVC项目,写了一个API方法,如下: /// <summary>/// 测试/// </summary>/// <param name="idList&qu ...

  5. JavaScript 函数 (一 JavaScript 函数的声明与使用)

    函数是由事件驱动的或者当它被调用时执行的可重复使用的代码块. JavaScript 函数的声明与使用 实例 <!DOCTYPE html> <html> <head> ...

  6. Java常用类笔记(学习尚硅谷java基础教程)

    一.Java根类Object类1.toString()方法 1)以文本对象返回,故toString()的定义为public String toString() {} 2)默认的字符串输出是:包.类名@ ...

  7. gofs使用教程-基于golang的开源跨平台文件同步工具

    概述 gofs是基于golang开发的一款开箱即用的跨平台文件同步工具,开源地址如下:https://github.com/no-src/gofs,欢迎点个Star或者提交Issue和PR,共同进步! ...

  8. 什么是 inode ?

    一般来说,面试不会问 inode .但是 inode 是一个重要概念,是理解 Unix/Linux 文件系统和硬盘储存的基础.理解inode,要从文件储存说起.文件储存在硬盘上,硬盘的最小存储单位叫做 ...

  9. 高度不定,宽100%,内一div高不确定,如何实现垂直居中?

    verticle-align: middle; 绝对定位50%加translateY(-50%) 绝对定位,上下左右全0,margin:auto

  10. jQuery--属性和CSS

    1.属性和CSS介绍 属性(重点掌握) attr(name) 获取指定属性名的值 attr(key,val) 给一个指定属性名设置值 attr(prop) 给多个属性名设置值.参数:prop json ...