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 ...
随机推荐
- MySQL Group Replication-MGR集群
简介 MySQL Group Replication(简称MGR)字面意思是mysql组复制的意思,但其实他是一个高可用的集群架构,暂时只支持mysql5.7和mysql8.0版本. 是MySQL官方 ...
- sas 9.4 sid 64bit 到期时间210804 带有EM
PROC SETINIT RELEASE='9.4';SITEINFO NAME='NATIONAL PINGTUNG UNI OF SCIENCE&TECH'SITE=12001462 OS ...
- let const区别!
这次做项目在申明变量的时候用到let const 总结下这两个区别 : 首先 let与const都是只在声明所在的块级作用域内有效. let声明的变量可以改变,值和类型都可以改变,没有限制.const ...
- Pandas学习笔记(三)
(1)系列对象( Series)基本功能 编号 属性或方法 描述 1 axes 返回行轴标签列表. 2 dtype 返回对象的数据类型(dtype). 3 empty 如果系列为空,则返回True. ...
- Python课程第二天作业
一.统计字符串格式 要求: # 1.统计元组中所有数据属于字符串的个数,提示: isinstance() # 数据: t1 = (1, 2, '3', '4', 5, '6') # 结果: 3 代码 ...
- .net core下载文件
上传的文件是在wwwroot下 通过保存的路径跟文件名称完成下载 public IActionResult DownloadFile() { var filePath = "/Upload ...
- Django的POST请求时因为开启防止csrf,报403错误,及四种解决方法
Django默认开启防止csrf(跨站点请求伪造)攻击,在post请求时,没有上传 csrf字段,导致校验失败,报403错误 解决方法1: 注释掉此段代码,即可. 缺点:导致Django项目完全无法防 ...
- springboot学习三:整合jsp
在pom.xml加入jstl <!--springboot tomcat jsp 支持开启--> <dependency> <groupId>org.apache. ...
- python爬虫爬取京东、淘宝、苏宁上华为P20购买评论
爬虫爬取京东.淘宝.苏宁上华为P20购买评论 1.使用软件 Anaconda3 2.代码截图 三个网站代码大同小异,因此只展示一个 3.结果(部分) 京东 淘宝 苏宁 4.分析 这三个网站上的评论数据 ...
- less和sass的区别
首先sass和less都是css的预编译处理语言,他们引入了mixins,参数,嵌套规则,运算,颜色,名字空间,作用域,JavaScript赋值等 加快了css开发效率,当然这两者都可以配合gulp和 ...