Codeforces Round #451 (Div. 2)
水题场。。。。
结果因为D题看错题意,B题手贱写残了。。。现场只出了A,C,E
A:水题。。
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pii pair<int,int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0) using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f3f; int main()
{
int n;
scanf("%d",&n);
int s=n%;
if(s<-s)printf("%d\n",n-s);
else printf("%d\n",n+-s);
return ;
}
/******************** ********************/
A
B:水题。。。直接暴力,不用exgcd
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pii pair<int,int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0) using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f3f; int main()
{
ll n,a,b;
scanf("%lld%lld%lld",&n,&a,&b);
for(ll i=;i<=;i++)
{
if(n-b*i>=&&(n-b*i)%a==)
{
puts("YES");
printf("%lld %lld\n",(n-b*i)/a,i);
return ;
}
}
puts("NO");
return ;
}
/******************** ********************/
B
C:把同一个人的电话合在一起,一个电话是另一个电话的后缀代表相同,直接暴力模拟即可
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pii pair<int,int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0) using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f3f; map<string,int>ma;
string s[N];
vector<string>v[N];
bool ok[+];
bool cmp(string a,string b)
{
return a.size()>b.size();
}
int main()
{
fio;
int n,sz=;
cin>>n;
for(int i=;i<=n;i++)
{
string p;
cin>>p;
if(ma[p])
{
int id=ma[p],k;
cin>>k;
while(k--)
{
cin>>p;
v[id].pb(p);
}
}
else
{
s[++sz]=p;
ma[p]=sz;
int k;
cin>>k;
while(k--)
{
cin>>p;
v[sz].pb(p);
}
}
}
cout<<sz<<"\n";
for(int i=;i<=sz;i++)
{
sort(v[i].begin(),v[i].end(),cmp);
memset(ok,,sizeof ok);
for(int j=;j<v[i].size();j++)
{
for(int k=j+;k<v[i].size();k++)
{
string a=v[i][j],b=v[i][k];
if(a.size()>=b.size())
{
if(a.substr(a.size()-b.size(),b.size())==b)ok[k]=;
}
}
}
cout<<s[i]<<" ";
int ans=;
for(int j=;j<v[i].size();j++)if(ok[j])ans++;
cout<<ans<<" ";
for(int j=;j<v[i].size();j++)
if(ok[j])
cout<<v[i][j]<<" ";
cout<<"\n";
}
return ;
}
/******************** ********************/
C
D:题意:一整天内,如果连续m分钟里,闹钟响了k次,那么人会被吵醒,要使人不被吵醒找到最小需要关闭的闹钟个数
题解:先sort,然后边处理边维护前缀和,处理的时候找到,当前到前m时刻有多少个闹钟,如果已经有k-1个,那么当前闹钟必须被关闭,可以简略的证明,如果一个闹钟对两个时间段有影响,那么它一定在两个时间段相交的部分里,所以,前缀和维护 是可行的
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pii pair<int,int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0) using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f3f; int a[N],sum[N*];
bool ok[N*];
int main()
{
int n,m,k;
scanf("%d%d%d",&n,&m,&k);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
ok[a[i]]=;
}
sort(a+,a++n);
int ans=;
for(int i=;i<=;i++)
{
if(!ok[i])sum[i]=sum[i-];
else
{
// cout<<sum[i-1]<<"----"<<sum[max(0,i-m)]<<"+++\n";
if(sum[i-]-sum[max(,i-m)]==k-)
{
ans++;
sum[i]=sum[i-];
}
else sum[i]=sum[i-]+;
}
}
printf("%d\n",ans);
return ;
}
/******************** ********************/
D
E:题意:n个数,每次操作对一个数+1或-1,要求最小操作次数使得n个数里有n/2个是完全平方数
题解:对于每一个数,如果是完全平方数,我们维护最小需要多少次操作使他变成不是完全平方数,否则,看最小多少次操作变成完全平方数,然后sort一下,比较即可
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pii pair<int,int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0) using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f3f; ll a[N];
map<ll,ll>ma;
ll c[N],po[N];
vector<ll>issq,notsq;
int main()
{
for(ll i=;i<=;i++)ma[i*i]=i,po[i]=i*i;
ll n,sq=;
scanf("%lld",&n);
for(int i=;i<=n;i++)
{
scanf("%lld",&a[i]);
if(ma[a[i]]||a[i]==)
{
sq++;
if(a[i]==)c[i]=;
else c[i]=;
issq.pb(c[i]);
}
else
{
int id=lower_bound(po,po+,a[i])-po;
c[i]=min(po[id]-a[i],a[i]-po[id-]);
notsq.pb(c[i]);
}
}
sort(issq.begin(),issq.end());
sort(notsq.begin(),notsq.end());
ll ans=;
if(sq>n/)
{
for(int i=;i<sq-n/;i++)
ans+=issq[i];
}
else
{
for(int i=;i<n/-sq;i++)
ans+=notsq[i];
}
printf("%lld\n",ans);
return ;
}
/******************** ********************/
F:题意:有一个很长的数,要求插入+,=使条件满足a+b=c,所有数不能有前导零
题解:对于长度为sz的数c,a要么长度为sz,sz-1,b要么长度sz,sz-1,只有四种情况(想到了这一点,但是高精度把我搞蒙蔽了,还是tle,学到了新姿势字符串Hash)
字符串Hash方便的判断两个字符串是否相同,推荐博客:字符串hash
我们以10为底,这样就可以满足线性关系了
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pii pair<int,int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0) using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f3f;
const ll ba=; ll p[N],Hash[N];
string s;
void init()
{
p[]=,Hash[]=s[]-'';
for(int i=;i<=+;i++)p[i]=p[i-]*ba%mod;
for(int i=;i<s.size();i++)
{
Hash[i]=Hash[i-]*ba%mod+s[i]-'';
if(Hash[i]>=mod)Hash[i]-=mod;
}
}
bool check(int a,int b)
{
//cout<<a<<" "<<b<<endl;
if(s[]==''&&a!=)return ;
if(s[a]==''&&b-a!=)return ;
ll aa=Hash[a-],bb=(Hash[b-]-Hash[a-]*p[b-a]%mod)%mod;
ll cc=(Hash[s.size()-]-Hash[b-]*p[s.size()-b]%mod)%mod;
// cout<<(aa+bb+mod)%mod<<"++++++ "<<(cc+mod)%mod<<endl;
return (aa+bb+mod)%mod==(cc+mod)%mod;
}
int main()
{
fio;
cin>>s;
init();
for(int i=;i<s.size();i++)
{
int sz=s.size()-i;
if(*sz<s.size())
{
int a=sz,b=s.size()-sz;
if(a<=sz&&b-a<=sz&&check(a,b))
{
cout<<s.substr(,a)<<"+"<<s.substr(a,b-a)<<"="<<s.substr(b,s.size())<<"\n";
return ;
}
a=s.size()-*sz,b=s.size()-sz;
if(a<=sz&&b-a<=sz&&check(a,b))
{
cout<<s.substr(,a)<<"+"<<s.substr(a,b-a)<<"="<<s.substr(b,s.size())<<"\n";
return ;
}
}
if(*sz-<s.size())
{
int a=sz-,b=s.size()-sz;
if(a<=sz&&b-a<=sz&&check(a,b))
{
cout<<s.substr(,a)<<"+"<<s.substr(a,b-a)<<"="<<s.substr(b,s.size())<<"\n";
return ;
}
a=s.size()-*sz+,b=s.size()-sz;
if(a<=sz&&b-a<=sz&&check(a,b))
{
cout<<s.substr(,a)<<"+"<<s.substr(a,b-a)<<"="<<s.substr(b,s.size())<<"\n";
return ;
}
}
}
return ;
}
/******************** ********************/
F
Codeforces Round #451 (Div. 2)的更多相关文章
- Codeforces Round #451 (Div. 2) A B C D E
Codeforces Round #451 (Div. 2) A Rounding 题目链接: http://codeforces.com/contest/898/problem/A 思路: 小于等于 ...
- Codeforces Round #451 (Div. 2)-898A. Rounding 898B.Proper Nutrition 898C.Phone Numbers(大佬容器套容器) 898D.Alarm Clock(超时了,待补坑)(贪心的思想)
A. Rounding time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- Codeforces Round #451 (Div. 2) A. Rounding【分类讨论/易错】
A. Rounding time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- Codeforces Round #451 (Div. 2) [ D. Alarm Clock ] [ E. Squares and not squares ] [ F. Restoring the Expression ]
PROBLEM D. Alarm Clock 题 OvO http://codeforces.com/contest/898/problem/D codeforces 898d 解 从前往后枚举,放进 ...
- Codeforces Round #451 (Div. 2) B. Proper Nutrition【枚举/扩展欧几里得/给你n问有没有两个非负整数x,y满足x·a + y·b = n】
B. Proper Nutrition time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 【Codeforces Round #451 (Div. 2) A】Rounding
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 模拟 [代码] /* 1.Shoud it use long long ? 2.Have you ever test several ...
- 【Codeforces Round #451 (Div. 2) B】Proper Nutrition
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 可以直接一层循环枚举. 也可以像我这样用一个数组来存y*b有哪些. 当然.感觉这样做写麻烦了.. [代码] /* 1.Shoud i ...
- 【Codeforces Round #451 (Div. 2) C】Phone Numbers
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用map<string,vector > dic;模拟就好. 后缀.翻转一下就变成前缀了. 两重循环剔除这种情况不输出就 ...
- 【Codeforces Round #451 (Div. 2) D】Alarm Clock
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 尺取法+二分. 类似滑动窗口. 即左端点为l,右端点为r. 维护a[r]-a[l]+1总是小于等于m的就好. (大于m就右移左端点) ...
随机推荐
- explorer.exe中发生未处理的win32异常
explorer.exe中发生未处理的win32异常的错误提示,是windows系统比较常见的错误事件,多数在开机遇到,也有在电脑使用过程中遇到. 了解explorer.exe进程 从百度百科了解到, ...
- Spring Mvc4 新特性(一)
前言 Spring Framework的Web层,由spring-web,spring-webmvc,spring-websocket和spring-webmvc-portlet模块组成. 很多人刚学 ...
- 算法分析之——heap-sort堆排序
堆排序是一种原地排序算法,不使用额外的数组空间,运行时间为O(nlgn).本篇文章我们来介绍一下堆排序的实现过程. 要了解堆排序.我们首先来了解一个概念,全然二叉树. 堆是一种全然二叉树或者近似全然二 ...
- 手势识别:GestureDetector
当用户触摸屏幕的时候,会产生许多手势,例如down,up,scroll,filing等等,我们知道View类有个View.OnTouchListener接口,通过重写他的onTouch(View v, ...
- HDFS各个进程存储在磁盘上的数据含义和注意事项
本文地址:http://www.cnblogs.com/qiaoyihang/p/6293402.html (一)Namenode的目录结构 HDFS进行初次格式化之后将会在$dfs.namenode ...
- js 实现无限加载分页(适合移动端)
一.原理:当滚动条到达底部时,执行下一页内容. 判断条件需要理解三个概念: 1.scrollHeight 真实内容的高度 2.clientHeight 视窗的高度,即在浏览器中所能看到的内 ...
- 吴超老师课程--HBASE的查询手机项目
查询1.按RowKey查询2.按手机号码查询3.按手机号码的区域查询 //查询手机13450456688的所有上网记录 public static void scan(String tableName ...
- Rare But Powerful Vim Commands.
@1: We all know about :wq, but we usually ignore :x. :x和:wq都是保存当前文件并退出. 这两个命令实际上并不完全等价,当文件被修改时两个命令时相 ...
- Apache和Nigix
Apache , Nginx 是开源的HTTP服务器软件 HTTP服务器本质上也是一种应用程序--它通常运行在服务器之上,绑定服务器的IP地址并监听某一个tcp端口来接收并处理HTTP请 ...
- 3. Longest Substring Without Repeating Characters(最长子串,双指针+hash)
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...