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 ...
随机推荐
- Complete Binary Search Tree
A Binary Search Tree (BST) is recursively defined as a binary tree which has the following propertie ...
- 在linux上构建gitolite
每台机器生成密钥前要设置邮箱和用户名: git config --global user.name "admin" git config --global user.email & ...
- text_CNN笔记
Text-CNN模型作为文本分类模型,通过验证实验以及业界的共识,在文本分类任务中,CNN模型已经能够取到比较好的结果,虽然在某些数据集上效果可能会比RNN稍差一点,但是CNN模型训练的效率更高.所以 ...
- MemCache在网站中的使用
MemCache安装好后,网站一直没法使用,后来查找资料,发现需要在配置文件里写几行代码,如下所示 <enyim.com> <memcached protocol="Tex ...
- 通过jedis远程访问redis服务器
一.jedis简介 类似于mysql数据库,一般开发都需要通过代码去访问redis服务器,对于主流的开发语言,redis提供了访问的客户端接口. https://redis.io/clients 而对 ...
- How does the compilation and linking process work?
The compilation of a C++ program involves three steps: Preprocessing: the preprocessor takes a C++ s ...
- JAVA体系学习-导向
一:当前学习内容 数值类型处理总结,字符类型处理总结,日期类型处理总结 spring 事务源码分析 spring源码系列 二:当前学习 主攻:并发编程->RPC原理->MQ原理->- ...
- (23/24) webpack实战技巧:如何在webpack环境中使用Json
在webpack1或者webpack2版本中,若想在webpack环境中加载Json文件,则需要加载一个json-loader的loader进来的.但是在webpack3.x版本中,则不需要在另外引入 ...
- [UNITY 5.4 UGUI] 控件重叠触摸穿透
问题. imge 和 button重叠时,imge 覆盖在button上面,导致点击事件无法传递到button. 1.给imge 添加 [Canvas Group]组件 2.修改[Canvas Gro ...
- Django url
urlpatterns = [ url(正则表达式, views视图函数,参数,别名),] 参数说明: 一个正则表达式字符串 一个可调用对象,通常为一个视图函数或一个指定视图函数路径的字符 ...