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 ...
随机推荐
- 用es5原生模仿-es6Promise异步处理
用es5原生模仿-es6Promise异步处理,不过在处理异常的时候有点小bug不是很完美,不过多级then 是没问题的和resolve, rejec 正常调用和异常处理调用是没问题的.本帖属于原创 ...
- python中re正则表达式
1.re匹配的语法 re.math 从头开始匹配,没有匹配到返回None re.seach 匹配包含,,没有匹配到返回None re.findall 把所有匹配到的字符,以列表的形式返回,没有匹配到返 ...
- jenkins pipline 发送邮件
推荐一个好网站https://www.w3cschool.cn/jenkins/jenkins-e7bo28ol.html 获取git 用户信息// Get checkout output value ...
- TODO:BGP 建立过程
//TODO: Quagga 实时监控配置文件
- Codeforces Round #436 D. Make a Permutation!
题意:给你n个数字,其中可能有相同的数字,要求你用其他的数字替换这些相同的数字,使得所得的序列字典序最小. Examples Input 43 2 2 3 Output 21 2 4 3 Input ...
- CDH 安装 kafka
前言 其实cloudera已经做了这个事了,只是把kafka的包和cdh的parcel包分离了,只要我们把分离开的kafka的服务描述jar包和服务parcel包下载了,就可以实现完美集成了. 具体实 ...
- java表达式中运算符优先级
运算符优先级:运算符*和/(以及%)的优先级高于+和-(优先级越高,越早运算) 在逻辑运算符中,!拥有最高优先级,之后是&&,接下来是||. 一般来说,相同优先级的运算符的运算顺序是从 ...
- 微信小程序如何实现和微信客服通话?
微信小程序如何实现和微信客服通话?
- MyCP -tx -xt 功能的Java实现
MyCP -tx -xt 功能的Java实现 功能简介 java MyCP -tx XXX1.txt XXX2.bin 用来把文本文件(内容为十进制数字)转化为二进制文件 java MyCP -xt ...
- delete 和 delete [] 的真正区别
c++中对new申请的内存的释放方式有delete和delete[两种方式,到底这两者有什么区别呢? 1.我们通常从教科书上看到这样的说明: delete 释放new分配的单个对象指针指向的内存 de ...