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 ...
随机推荐
- 各平台操作系统查询主机WWPN
查询主机WWPN 目录 3.4.3.8.2.3 查询主机WWPN 3.4.3.8.2.3.1 查看主机HBA相应端口的WWPN(Windows) 3.4.3.8.2.3.2 查看主机HBA相应端口的W ...
- .net core2 单元测试
1.下载 https://marketplace.visualstudio.com/items?itemName=RandomEngy.UnitTestBoilerplateGenerator 2 ...
- selenium测瀑布流UI页面的Python代码
from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdri ...
- 实现A-Z滑动检索菜单
我们实现一个A-Z滑动检索菜单,这是一个移动端非常常见的功能,页面效果图如下 在实现代码之前我们先了解下JS滚动事件和滑动事件 scrollTop 一个元素的scrollTop是这个元素的顶部 到 可 ...
- Java——String类中的compareTo方法总结
String类的定义: java.lang 类 String java.lang.Object java.lang.String 所有已实现的接口:Serializable, C ...
- js动态添加、删除行
<meta charset="utf-8"> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transiti ...
- Android 开发 图片网络缓存加载框架Fresco
简介 Fresco是一个在Android应用程序中显示图像的强大系统. Fresco负责图像的加载和显示.它将从网络.本地存储或本地资源加载图像,图像加载完成前会显示一个占位图片.它有两个级别的缓存: ...
- .htaccess: Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration
php项目 .htaccess文件配置如下: #文件缓存时间配置 <FilesMatch ".(flv|gif|jpg|jpeg|png|ico|swf|js|css)$"& ...
- V先生:信息流广告标题党必备的500个热词
稍微没有全都偏,简直仅仅只永远, 已经曾经就竟然,将要立刻刚偶然, 渐渐终于决忽然,难道连续又再三, 也许必须很非常,最太十分更马上, 越极总挺常常再,屡次一定也不还. 你一定不知道.如何.最.咋.是 ...
- sqlPlus基本操作
SQL*PLUS连接方法 1. $ sqlplus "user/password[@service] [as sysdba]" 2. $ sqlplus /nolog SQL> ...