水题场。。。。

结果因为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)的更多相关文章

  1. Codeforces Round #451 (Div. 2) A B C D E

    Codeforces Round #451 (Div. 2) A Rounding 题目链接: http://codeforces.com/contest/898/problem/A 思路: 小于等于 ...

  2. 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 ...

  3. 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 ...

  4. 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 解 从前往后枚举,放进 ...

  5. 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 ...

  6. 【Codeforces Round #451 (Div. 2) A】Rounding

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 模拟 [代码] /* 1.Shoud it use long long ? 2.Have you ever test several ...

  7. 【Codeforces Round #451 (Div. 2) B】Proper Nutrition

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 可以直接一层循环枚举. 也可以像我这样用一个数组来存y*b有哪些. 当然.感觉这样做写麻烦了.. [代码] /* 1.Shoud i ...

  8. 【Codeforces Round #451 (Div. 2) C】Phone Numbers

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用map<string,vector > dic;模拟就好. 后缀.翻转一下就变成前缀了. 两重循环剔除这种情况不输出就 ...

  9. 【Codeforces Round #451 (Div. 2) D】Alarm Clock

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 尺取法+二分. 类似滑动窗口. 即左端点为l,右端点为r. 维护a[r]-a[l]+1总是小于等于m的就好. (大于m就右移左端点) ...

随机推荐

  1. VS c++ opencv画图

    任务:用c++在图片上画线 之前用过python的opencv,所以直接想到了用c++的opencv来画线. 但关键就是VS中如何配置c++ opencv库的问题: vs中opencv库的配置:htt ...

  2. python可变参数*args, **kwargs

    python可变参数*args, **kwargs def foo(* args, ** kwargs): print ' args = ',  args print ' kwargs = ',  k ...

  3. Python模块学习之bs4

    1.安装bs4 我用的ubuntu14.4,直接用apt-get命令就行 sudo apt-get install Python-bs4 2.安装解析器 Beautiful Soup支持Python标 ...

  4. 前端基础-css(3)

    一.文本属性和字体属性(常用的) 1.文本属性 text-align:left|right|center|justify(两端对齐,只适用于英文);   /*对齐方式*/ color:色值;   /* ...

  5. unity3d相关资源

    http://pan.baidu.com/s/1kTG9DVD   GUI源码

  6. s5_day2作业

    # 1:编写for循环,利用索引遍历出每一个字符 # msg = 'hello egon 666' # for i in range(len(msg)): # print(i,msg[i]) # 2: ...

  7. 第五课 Makefile文件的制作(补充)

    序言: 前面的几节课讲解Makefile的一些基本知识也做了一些小例子实践了几下,那么到现在普通的练习则是没有问题.但是如果做项目文件较多又分层次等等还是会碰上好多问题的,这节课补充一些知识. 知识点 ...

  8. 扯一扯 C#委托和事件?策略模式?接口回调?

    早前学习委托的时候,写过一点东西,今天带着新的思考和认知,再记点东西.这篇文章扯到设计模式中的策略模式,观察者模式,还有.NET的特性之一--委托.真的,请相信我,我只是在扯淡...... 场景练习 ...

  9. 多线程 wait和sleep区别

    wait和sleep区别共同点: 1. 他们都是在多线程的环境下,都可以在程序的调用处阻塞指定的毫秒数,并返回. 2. wait()和sleep()都可以通过interrupt()方法 打断线程的暂停 ...

  10. <context:annotation-config/> 的理解

    转载:http://www.cnblogs.com/iuranus/archive/2012/07/19/2599084.html 当我们需要使用BeanPostProcessor时,直接在Sprin ...