Educational Codeforces Round 36
A. Garden
题目链接:http://codeforces.com/contest/915/problem/A
题意:N个花洒,每个花洒浇花有一定的范围,现在有面积为K的花园,从N个花洒中选一个花洒来给花园浇花,用时最少的多少,题目要求每个单位的花园只能被浇一次,并且花园以外的地方不能有水,题目保证有答案。
思路:选一个能被K整出的最大容量C,然后输出K/C。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int INF=1e9+7;
int n,m,x,minn;
int main()
{
cin>>n>>m;
minn=m;
while(n--)
{
cin>>x;
if(m%x==0)
minn=min(minn,m/x);
}
cout<<minn<<endl;
return 0;
}
B. Browser
题目链接:http://codeforces.com/contest/915/problem/B
题意:你要保留l-r这段区间的书签,开始你的光标在pos处,你每秒可以向左或向右移动一个位置,假如你光标在某处你可以删除该位置左边的所有标签,耗时为1,同理你也可以删除该位置右边的所有标签,耗时为1,问保留l-r这段区间的书签你耗时最少为多少。
思路:分情况讨论。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,pos,l,r,t;
int main()
{
cin>>n>>pos>>l>>r;
if(l==1&&r==n)
t=0;
else if(l>1&&r==n)
{
if(pos<l)
t=l-pos+1;
else if(pos==l)
t=1;
else
t=pos-l+1;
}
else if(l==1&&r<n)
{
if(pos>r)
t=pos-r+1;
else if(pos==r)
t=1;
else
t=r-pos+1;
}
else
{
if(pos<=l)
t=l-pos+1+r-l+1;
else if(pos>=r)
t=pos-r+1+r-l+1;
else
t=min(pos-l,r-pos)+2+r-l;
}
cout<<t<<endl;
return 0;
}
C. Permute Digits
题目链接:http://codeforces.com/contest/915/problem/C
题意:从A的全排列中选择一个最大的数,使得这个数不大于B。
思路:如果A的长度小于B的长度,将A中的数字从大到小输出。否则,将A中各个数字的个数保留,遍历B,每次从9-0中选择一个小于或等于B当前位置的最大的数保存并且做好标记,如果当前这个位置的数比找到的那个数大,那么将9-0从小到大剩下的全部保存起来。如果找到的数等于B当前位置的数,则继续往后遍历B。如果没有找到当前小于或等于B的数,说明前一位保存的数太大了,这个数我们记作x吧,然后我们遍历X-1~0的区间找一个个数不为0的最大的数保存,之后将剩下的数按9-0全部保存,因为前一位的数,一定比B对应的那位数小,所以之后得到的那个数一定比B小。还是多亏了大佬的博客!!Orz。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define ll long long
ll a,b;
char sa[25],sb[25];
int la,lb,ca[25],vis[25],flag,f;
int main()
{
cin>>a>>b;
sprintf(sa,"%lld",a);
sprintf(sb,"%lld",b);
la=strlen(sa);
lb=strlen(sb);
for(int i=0; i<la; i++)
{
ca[i]=sa[i]-'0';
vis[ca[i]]++;
//cout<<vis[ca[i]]<<" "<<ca[i]<<endl;
}
sort(ca,ca+la);
if(la<lb)
{
for(int i=la-1; i>=0; i--)
cout<<ca[i];
}
else
{
for(int i=0;i<lb;i++)
{
f=0;
flag=0;
for(int j=9;j>=0;j--)
{
if(vis[j]&&j==sb[i]-'0')
{
//cout<<j<<endl;
vis[j]--;
f=1;
sa[i]=j+'0';
break;
}
else if(vis[j]&&j<sb[i]-'0')
{
//cout<<j<<endl;
vis[j]--;
flag=1;
f=1;
sa[i]=j+'0';
break;
}
}
while(!f)
{
i--;
vis[sa[i]-'0']++;
//cout<<sa[i]-'0'<<endl;
for(int j=sa[i]-'0'-1;j>=0;j--)
{
if(vis[j])
{
vis[j]--;
flag=1;
f=1;
sa[i]=j+'0';
break;
}
}
}
if(flag)
{
i++;
for(int j=9;j>=0;j--)
while(vis[j])
{
sa[i++]=j+'0';
vis[j]--;
}
}
}
sa[lb]='\0';
cout<<sa<<endl;
}
cout<<endl;
return 0;
}
Educational Codeforces Round 36的更多相关文章
- Educational Codeforces Round 36 (Rated for Div. 2) E. Physical Education Lessons
提供两种思路 一种线段树区间更新 另一种用map维护连续的区间,也是题解的思路 第二种很难写(我太渣,看了别人的代码,发现自己写的太烦了) #include<iostream> #incl ...
- Educational Codeforces Round 36 (Rated for Div. 2)
A. Garden time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...
- Educational Codeforces Round 36 (Rated for Div. 2) G. Coprime Arrays
求a_i 在 [1,k]范围内,gcd(a_1,a_2...,a_n) = 1的a的数组个数. F(x)表示gcd(a_1,a_2,...,a_n) = i的a的个数 f(x)表示gcd(a_1,a_ ...
- 【Educational Codeforces Round 36 D】 Almost Acyclic Graph
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 找到任意一个环. 然后枚举删掉其中的某一条边即可. (因为肯定要删掉这个环的,那么方法自然就是删掉其中的某一条边 (其它环,如果都包 ...
- 【Educational Codeforces Round 36 C】 Permute Digits
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] //从大到小枚举第i(1..len1)位 //剩余的数字从小到大排序. //看看组成的数字是不是小于等于b //如果是的话. //说 ...
- 【Educational Codeforces Round 36 B】Browser
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 分类在区间里面和左边.右边三种情况. 看看l的左边有没有标签.r的右边有没有标签. 就能做完了. [代码] #include < ...
- 【Educational Codeforces Round 36 A】 Garden
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举用哪一个桶就好 [代码] #include <bits/stdc++.h> using namespace std; ...
- Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题
Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题 [Problem Description] 总共两次询 ...
- [Educational Codeforces Round 16]E. Generate a String
[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...
随机推荐
- nodeJs 操作Mysql数据库
nodeJs下操作数据库需要安装npm模块: mysql npm install mysql --save-dev 新建express项目 express --view=ejs 在项目根目录下新建数据 ...
- js实现reqire中的amd,cmd功能
js实现reqire中的amd,cmd功能 ,大概实现了 路径和模块 引入等重要功能. 本帖属于原创,转载请出名出处. <!DOCTYPE html PUBLIC "-//W3C//D ...
- 快速理解高性能HTTP服务端的负载均衡技术原理(转)
1.前言 在一个典型的高并发.大用户量的Web互联网系统的架构设计中,对HTTP集群的负载均衡设计是作为高性能系统优化环节中必不可少的方案.HTTP负载均衡的本质上是将Web用户流量进行均衡减压,因此 ...
- Spring再接触 Scope范围
<bean id="userService" class="com.bjsxt.service.UserService" scope="prot ...
- (转)Microsoft Print to PDF
好像win10.win7 都有
- [原创] debian 9.3 搭建Jira+Confluence+Bitbucket项目管理工具(一) -- 安装jdk(含jre)及 MySql 5.6.39
[原创] debian 9.3 搭建Jira+Confluence+Bitbucket项目管理工具(一) -- 安装jdk(含jre)及 MySql 5.6.39 回老家已经有一段时间了, 四五线 ...
- Django Cache缓存系统学习--数据库缓存
Django是动态网站,用户每一次请求页面,服务器都会执行以下操作:数据库查询.渲染模版.执行业务逻辑,最后生成用户可查看的页面.当访问量比较大的时候,会消耗掉大量的资源,这时候就会考虑到缓存问题. ...
- Mysql 存储过程批量建表
CREATE DEFINER=`root`@`%` PROCEDURE `createTables`() begin declare i int; declare suffix varchar(20) ...
- dotnet不是内部或外部的命令,也不是可运行的程序或批处理文件
该问题是由于电脑环境变量配置错误所导致.最初在网上查找的方法,是在系统环境变量path中添加以下语句: %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\ ...
- python--第十六天总结(bootstrap)
一. 实现原理 网格布局是通过容器的大小,平均分为12份(可以修改),再调整内外边距,和表格布局有点类似但是也存在区别. 实现步骤如下: (1) 数据行.row 必须包含在容器.container 中 ...