Codeforces Round #491 (Div. 2)
Codeforces Round #491 (Div. 2)
https://codeforces.com/contest/991
A
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define IT set<ll>::iterator
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 1000006
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef pair<ll,int> pli;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=;
const double oula=0.57721566490153286060651209;
using namespace std; int main(){
std::ios::sync_with_stdio(false);
int a,b,c,n;
cin>>a>>b>>c>>n;
int ans=n-a-b+c;
if(ans>&&a<n&&b<n&&c<n&&n-ans>=a&&n-ans>=b&&n-ans>=c&&c<=a&&c<=b&&ans<=n) cout<<ans<<endl;
else cout<<-<<endl;
}
B
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define IT set<ll>::iterator
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 1000006
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef pair<ll,int> pli;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=;
const double oula=0.57721566490153286060651209;
using namespace std; int n;
int a[]; int main(){
std::ios::sync_with_stdio(false);
cin>>n;
ll sum=;
for(int i=;i<=n;i++) {
cin>>a[i];
sum+=a[i];
}
sort(a+,a+n+);
if(round(sum*1.0/n)==){
cout<<<<endl;
return ;
}
for(int i=;i<=n;i++){
sum+=-a[i];
if(round(sum*1.0/n)==){
cout<<i<<endl;
break;
}
}
}
C
题意:a有n个糖果,在开始的时候 a 选择一个整数k,表示他每天会吃k个糖果,b也想吃糖果,他每天会吃当前数量的10%(下取整)的糖果,a先开始吃,问a选择的k值最小为多少,使得他吃的糖果的数量大于等于总数的一半。
思路:二分最小值即可。注意:取10%的时候要用tmp/10,不能用tmp*0.1,会有精度问题(被坑了好久)
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define IT set<ll>::iterator
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 1000006
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef pair<ll,int> pli;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=;
const double oula=0.57721566490153286060651209;
using namespace std; ll n; bool Check(ll mid){
ll sum1=,sum2=;
ll tmp=n;
ll t;
while(tmp){
if(tmp>=mid){
tmp-=mid;
sum1+=mid;
}
else {
sum1+=tmp;
tmp=;
}
if(tmp>=){
t=tmp/;
sum2+=t;
tmp-=t;
}
}
if(sum1>=sum2) return true;
return false;
} int main(){
std::ios::sync_with_stdio(false);
cin>>n;
ll L=,R=n,mid;
while(L<=R){
mid=L+R>>;
if(Check(mid)){
R=mid-;
}
else{
L=mid+;
}
}
cout<<L<<endl;
}
D
题意:给定宽为两行的矩阵,问能放多少木块。
思路:因为只有两行,所以直接贪心即可,把每列有空的地方能放则放,要注意,当第一列遍历到i位置时,第二列i-1位置是否为空
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define IT set<ll>::iterator
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 1000006
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef pair<ll,int> pli;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=;
const double oula=0.57721566490153286060651209;
using namespace std; int book[][];
int len;
string s1,s2; bool Check(int x){
if(x->=){
if(!book[][x]&&!book[][x-]&&!book[][x]&&s1[x]==''&&s2[x-]==''&&s2[x]==''){
book[][x]=;book[][x-]=;book[][x]=;
return true;
}
}
if(x+<len){
if(!book[][x]&&!book[][x+]&&!book[][x]&&s1[x]==''&&s2[x+]==''&&s2[x]==''){
book[][x]=;book[][x+]=;book[][x]=;
return true;
}
if(!book[][x]&&!book[][x+]&&!book[][x+]&&s1[x]==''&&s1[x+]==''&&s2[x+]==''){
book[][x]=;book[][x+]=;book[][x+]=;
return true;
}
if(!book[][x]&&!book[][x+]&&!book[][x]&&s1[x]==''&&s1[x+]==''&&s2[x]==''){
book[][x]=;book[][x+]=;book[][x]=;
return true;
}
} return false;
} int main(){
std::ios::sync_with_stdio(false);
cin>>s1>>s2;
len=s1.length();
int ans=;
for(int i=;i<len;i++){
if(!book[][i]){
if(Check(i)){
ans++;
}
}
}
cout<<ans<<endl;
}
E
题意:给你一个数字序列A(长度不超过18位),问有多少个序列B满足:
1、A中所有数字都一定要在B中出现过;
2、B中所有数字也一定要在A中出现过;
3、序列B不能以0开头
比如:如果看到数字2028,它可能实际的车号可能是2028,8022,2820或者是820。 而80号、22208号、52号肯定不是这辆车的号码。 而且,实际的车号不能以数字0开头,例如,数字082不能也是实际的车号。 给定看到的数字n,求出所有可能的车号种数。
思路:枚举各个位上出现的数的个数。先不考虑前导0的情况下,车号总数为:车号位数之和的阶乘除以各个位数的个数。然后在减去前导0的情况即可
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define IT set<ll>::iterator
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 1000006
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef pair<ll,int> pli;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=;
const double oula=0.57721566490153286060651209;
using namespace std; int num[];
ll fac[];
ll sum[];
ll ans; void dfs(int pos){
if(pos==){
ll co=;
for(int i=;i<;i++){
co+=sum[i];
}
ll tmp=fac[co];
for(int i=;i<;i++) tmp/=fac[sum[i]];
if(sum[]>=) tmp-=(tmp*sum[]/co);
ans+=tmp;
return;
}
for(int i=;i<=num[pos];i++){
sum[pos]=i;
dfs(pos+);
}
if(num[pos]==) dfs(pos+);
} int main(){
std::ios::sync_with_stdio(false);
string str;
fac[]=;
for(int i=;i<;i++) fac[i]=fac[i-]*i;
cin>>str;
for(int i=;i<str.length();i++){
num[str[i]-'']++;
}
dfs();
cout<<ans<<endl;
}
F
题意:给定n,把n简短化,比如:2000000000变成2*10^9,注意,不能使用括号,不能有2^3^4这样的形式
思路:先预处理出满足条件的a^b的形式,然后枚举这样的式子,在需要的情况下添加‘*’和‘+’,贪心判断长度即可
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define IT set<ll>::iterator
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 1000006
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef pair<ll,int> pli;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=;
const double oula=0.57721566490153286060651209;
using namespace std; map<ll,string>mp;
int main(){
std::ios::sync_with_stdio(false);
ll n;
cin>>n;
ll nn=sqrt(n);
string tmp;
for(ll i=;i<=nn;i++){
ll num=i*i;
int co=;
while(num<=n){
tmp=to_string(i)+"^"+to_string(co);
if(!mp.count(num)) mp[num]=to_string(num);
if(mp[num].size()>tmp.size()) mp[num]=tmp;
co++;
num*=i;
}
}
string ans=to_string(n);
map<ll,string>::iterator it;
for(it=mp.begin();it!=mp.end();it++){
tmp="";
ll a=n/it->first,b=n%it->first;
if(a>){
if(mp.count(a)) tmp=mp[a];
else tmp=to_string(a);
tmp+="*";
}
tmp+=it->second;
if(b) tmp=tmp+"+"+(mp.count(b)?mp[b]:to_string(b));
if(ans.size()>tmp.size()) ans=tmp;
} cout<<ans<<endl;
}
Codeforces Round #491 (Div. 2)的更多相关文章
- 【Codeforces】Codeforces Round #491 (Div. 2) (Contest 991)
题目 传送门:QWQ A:A - If at first you don't succeed... 分析: 按照题意模拟 代码: #include <bits/stdc++.h> usin ...
- Codeforces Round #491 (Div. 2) E - Bus Number + 反思
E - Bus Number 最近感觉打CF各种车祸.....感觉要反思一下, 上次读错题,这次想当然地以为18!肯定暴了longlong 而没有去实践, 这个题我看到就感觉是枚举每个数字的个数,但是 ...
- Codeforces Round #491 (Div. 2)部分题解
这场比赛好鬼畜啊,,A题写崩了wa了4遍,心态直接爆炸,本来想弃疗了,结果发现BCD都是傻逼题.. A. If at first you don't succeed...(容斥原理) 题目大意: 有$ ...
- 【Codeforces】Round #491 (Div. 2) 总结
[Codeforces]Round #491 (Div. 2) 总结 这次尴尬了,D题fst,E没有做出来.... 不过还好,rating只掉了30,总体来说比较不稳,下次加油 A:If at fir ...
- 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 ...
随机推荐
- Halcon 17与 c# 混合编程
这篇主要是C#和Halcon的混合编程,在此基础上对按键不同功能的划分,以及图片适应窗口和从本地打开图片. halcon源程序: dev_open_window(0, 0, 512, 512, ' ...
- oracle表的基本操作
--修改名称rename l_user_info to t_user_info --添加带有约束的表 create table t_user_menu( id number(20) primary k ...
- UI自动化之元素定位(xpath、css)
很早之前就已经写过自动化了,不过点着功能久了就会容易忘记元素定位,尤其是xpath和css定位,所以就花点时间做下总结收集. xpath有两种定位: 一.绝对路径(不推荐使用,除非已经使用了所有方式仍 ...
- 强一致性hash实现java版本及强一致性hash原理
一致性 hash 分布式过程中我们将服务分散到若干的节点上,以此通过集体的力量提升服务的目的.然而,对于一个客户端来说,该由哪个节点服务呢?或者说对某个节点来说他分配到哪些任务呢? 强哈希 考虑到单服 ...
- 使用JavaScript制作页面特效2
1.Date对象的常用方法 setFullYear() setMonth() setDate() setHours() setMinutes() setSeconds() 定时函数 setTimeou ...
- Anatomy of a Database System学习笔记 - 事务:并发控制与恢复
这一章看起来是讲存储引擎的.作者抱怨数据库被黑为“monolithic”.不可拆分为可复用的组件:但是实际上除了事务存储引擎管理模块,其他模块入解析器.重写引擎.优化器.执行器.访问方式都是代码相对独 ...
- 将自己的SpringBoot应用打包发布到Linux下Docker中
目录 将自己的SpringBoot应用打包发布到Linux下Docker中 1. 环境介绍 2. 开始前的准备 2.1 开启docker远程连接 2.2 新建SpringBoot项目 3. 开始构建我 ...
- 关于JWTtoken的管理问题
JWT简介: Json web token (JWT), 是为了在网络应用环境间传递声明而执行的一种基于JSON的开放标准.因为网络上有很多关于jwt的详细介绍了,所以我这里就不再赘述.但是JWT的大 ...
- 字符型转换为字符串ToString
字符型转换为字符串 // C 货币 2.5.ToString("C"); // ¥2.50 // D 10进制数 25.ToString("D5"); // 2 ...
- React State(状态)
function FormattedDate(props){ return ( <h1>现在是{props.date}</h1> ) } class Clock extends ...