Codeforces Round #451 (Div. 2)

A Rounding

题目链接:

http://codeforces.com/contest/898/problem/A

思路:

小于等于5向下,大于补上差值输出

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll n;
scanf("%I64d",&n);
int r=n%10;
if(r<=5) printf("%I64d\n",n-r);
else printf("%I64d\n",n+10-r);
return 0;
}

B Proper Nutrition

题目链接:

http://codeforces.com/contest/898/problem/B

思路:

暴力枚举

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll a,b,n;
scanf("%I64d",&n);
scanf("%I64d %I64d",&a,&b);
bool flag=false;
ll index=n/a;
for(ll i=0;i<=index;++i) {
ll temp=n-i*a;
if(temp/b*b==temp) {
printf("YES\n");
printf("%I64d %I64d\n",i,temp/b);
flag=true;
break;
}
}
if(!flag) printf("NO\n");
return 0;
}

C Phone Numbers

题目链接:

http://codeforces.com/contest/898/problem/C

思路:

暴力大法。

就是string排序的时候重写一下cmp,另外sort之后不要unique,不然会wa5

代码:

#include <bits/stdc++.h>
using namespace std;
vector<string> vec[21];
map<int,string> mp;
set<string> se;
bool cmp(string a, string b) {
if(a.length()!=b.length()) return a.length()<b.length();
return a<b;
}
int main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n,cnt,id;cin>>n;
string name;
int tot;
string number;
cnt=1;
for(int i=0;i<n;++i) {
cin>>name;
cin>>tot;
if(se.count(name)==0) {
mp[cnt]=name;
se.insert(name);
++cnt;
}
for(auto it=mp.begin();it!=mp.end();it++) {
if(it->second==name) {
id=it->first;
break;
}
}
for(int j=0;j<tot;++j) {
cin>>number;
vec[id].push_back(number);
}
}
cout<<se.size()<<endl;
for(int i=1;i<cnt;++i) {
sort(vec[i].begin(),vec[i].end(),cmp);
for(unsigned int j=0;j<vec[i].size();++j) {
string s;
s=vec[i][j];
reverse(s.begin(),s.end());
for(unsigned int z=j+1;z<vec[i].size();++z) {
string ss;
ss=vec[i][z];
reverse(ss.begin(),ss.end());
if(ss.substr(0,s.length())==s) {
vec[i].erase(vec[i].begin()+j);
--j;
break;
}
}
}
cout<<mp[i]<<" "<<vec[i].size()<<" ";
for(unsigned int j=0;j<vec[i].size();++j) {
if(j>0) cout<<" "<<vec[i][j];
else cout<<vec[i][j];
}
cout<<endl;
}
return 0;
}

D Alarm Clock

题目链接:

http://codeforces.com/contest/898/problem/D

题目大意:

不允许在m分钟内有k个闹钟响,每个闹钟响一分钟,求最少关掉的闹钟数目

思路:

首先其实按照从小到大的时间顺序查看,因为这相当于一个m大的滑块在整个数组上划一遍,所以使用队列就可以,其实就是贪心的思想。

代码:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000005;
int a[maxn];
int main() {
int n,m,k,num,res=0,tot=0;
scanf("%d %d %d",&n,&m,&k);
for(int i=1;i<=n;++i) a[i]=0;
for(int i=1;i<=n;++i) scanf("%d",&num),a[num]=1;
for(int i=1;i<=1e6;++i) {
if(a[i]) ++tot;
if(i>m&&a[i-m]) --tot;
if(tot==k) {
--tot;
++res;
a[i]=0;
}
}
printf("%d\n",res);
return 0;
}

E Squares and not squares

题目链接:

http://codeforces.com/contest/898/problem/E

思路:

统计出给定序列的完全平方数和非完全平方数,看看是要补平方数还是补非完全平方数。记录下每个数距离最近的完全平方数的插值,同时记录下改为非完全平方数的最小差值。根据是前面所述的两种情况中的一种进行排序,选择出最小的数据插值求和即可。

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 200005;
struct node {ll num,a,b;int d;}ans[maxn];
bool cmp1(node x, node y) {return x.a<y.a;}
bool cmp2(node x, node y) {return x.b<y.b;}
int main() {
int n;scanf("%d",&n);
int d1,d2,cnt;
ll sum=0;
d1=0;
for(int i=0;i<n;++i) {
scanf("%I64d",&ans[i].num);
ll number=(ll)sqrt(ans[i].num);
ll x=number*number;
if(x==ans[i].num) {
++d1;
ans[i].d=1;
} else ans[i].d=0;
ll y=(number+1)*(number+1);
ans[i].a=min(ans[i].num-x,y-ans[i].num);
if(max(ans[i].num-x,y-ans[i].num)>1) ans[i].b=1;
else ans[i].b=2;
}
d2=n-d1;
if(d2>d1) {
cnt=n/2-d1;
sort(ans,ans+n,cmp1);
for(int i=0;i<n;++i) {
if(ans[i].a!=0&&ans[i].d==0) {
sum+=ans[i].a;
--cnt;
if(cnt==0) break;
}
}
} else if(d1>d2) {
cnt=n/2-d2;
sort(ans,ans+n,cmp2);
for(int i=0;i<n;++i) {
if(ans[i].b!=0&&ans[i].d==1) {
sum+=ans[i].b;
--cnt;
if(cnt==0) break;
}
}
}
printf("%I64d\n",sum);
return 0;
}

Codeforces Round #451 (Div. 2) A B C D E的更多相关文章

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

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

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

  4. Codeforces Round #451 (Div. 2)

    水题场.... 结果因为D题看错题意,B题手贱写残了...现场只出了A,C,E A:水题.. #include<bits/stdc++.h> #define fi first #defin ...

  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. Python安装cx_Oracle与操作数据测试小结

    这里简单总结一下Python操作Oracle数据库这方面的相关知识.只是简单的整理一下之前的实验和笔记.这里的测试服务器为CentOS Linux release 7.5. 个人实验.测试.采集数据的 ...

  2. [考试反思]1109csp-s模拟测试106:撞词

    (撞哈希了用了模拟测试28的词,所以这次就叫撞词吧) 蓝色的0... 蓝色的0... 都该联赛了还能CE呢... 考试结束前15分钟左右,期望得分300 然后对拍发现T2伪了写了一个能拿90分的垃圾随 ...

  3. [考试反思]0805NOIP模拟测试13:窒息

    呼啊...苟住了.rank #3 第二次分机房的收官之战.发挥比较稳定 然而差点就不稳定了!!! 过了一遍题目,难度大约是升序,但是一道都不会做!!! 本来感觉T1是一道数学题,以为45分钟以内可以切 ...

  4. 使用Typescript重构axios(二十二)——请求取消功能:收尾

    0. 系列文章 1.使用Typescript重构axios(一)--写在最前面 2.使用Typescript重构axios(二)--项目起手,跑通流程 3.使用Typescript重构axios(三) ...

  5. MATLAB基本使用及SIMULINK建模仿真实验

    MATLAB基本使用及SIMULINK建模仿真实验 这是我总结的操作方法: 1 )  M脚本文件的编写 1.新建M-file: 2.输入指令: 3.保存(注意:保存路径需要与工作路径一致) 2 )在S ...

  6. phpexcel导出数字带E的解决方法

    phpexcel导出数字带E的解决方法 excel之所以带E 是因为按照数字格式来显示了(数字过长的时候) 数字左边或者右边加空格就变成字符串了 那么excel就会按照字符串格式来显示了 就不会带E了

  7. 实现支持多用户在线的FTP程序(C/S)

    1. 需求 1. 用户加密认证 2. 允许多用户登录 3. 每个用户都有自己的家目录,且只能访问自己的家目录 4. 对用户进行磁盘分配,每一个用户的可用空间可以自己设置 5. 允许用户在ftp ser ...

  8. T-SQL Part X: UNION, EXCEPT and INTERSECT

    MSDN上关于EXCEPT和INTERSECT的文档.MSDN上关于UNION的文档. 值得注意的是,UNION其实有两种,一种是普通的UNION,另外一种是UNION ALL.加上EXCEPT和IN ...

  9. 【前端知识体系-JS相关】JS-Web-API总结

    2.1 DOM操作 2.1.1 DOM的本质是什么? <!-- DOM树:二叉树 --> /* <?xml version="1.0" encoding=&quo ...

  10. 关键路径法(Critical Path Method, CPM)

    1.活动节点描述及计算公式 通过分析项目过程中哪个活动序列进度安排的总时差最少来预测项目工期的网络分析. 产生目的:为了解决,在庞大而复杂的项目中,如何合理而有效地组织人力.物力和财力,使之在有限资源 ...