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 ...
随机推荐
- mysql监控执行的sql语句
转载 https://blog.csdn.net/nzjdsds/article/details/77513869 MySQL用SQL开启general_log并设置路径 2017年08月24日 00 ...
- 一个jQuery对象绑定多个事件
1.两个事件有两种不同的方法 jQuery("#id").click(func1(){}).mouseover(func2(){}) ; 2.两个事件调用同一种方法 jquery( ...
- c# System.Console
System.Console类公开了和操作控制台相关的有用的静态字段和静态方法.下面是System.Console中一些较为重要的方法. public static void Beep()该方法播放蜂 ...
- 【博客开篇】服务器配置:Windows2008R2+PHP5.6+SQLServer2008(X64)
现下流行LAMP,如果选择Windows服务器,那么一般都会选择IIS+Asp.Net+SQL Server(可以简称为WINS),这些配置起来,都是非常方便的. 但也有一些特殊的服务器配置,例如:W ...
- 教师派day1
终于决定好要冲刺了. 昨天开了一个短会,又详细分配了一下任务. 问题是:我的android装了好久好久才可以用~ 今天要把android里的各个文件.控件搞清楚.
- jq 获取下一个兄弟原素 下拉箭头旋转
$('.weui-cells__title').on("click", function(e,rr){ isshow=$(this).attr('isshow') if(issho ...
- SpringCloud-day07-Feign
7.Feign 7.1.Feign简介 声明式服务调用Feign简单介绍下: Feign是一个声明式的Web Service客户端,它使得编写Web Serivce客户端变得更加简单.我们只需要使用F ...
- docker挂载目录的深入研究
转载一篇很好的文章: https://www.cnblogs.com/ivictor/p/4834864.html
- Redhat系统上开启Telnet服务
https://blog.csdn.net/wolfofsiberian/article/details/51635952 1.操作系统 Redhat Step1:修改配置文件/etc/xinetd. ...
- java将一个List赋值给另一个List
声明和实例化: 声明:ArrayList a, 仅仅只是声明了一个list变量,其未来作用相当于C++中的引用变量,亦或者相当于一个对象块的索引,但并未为其分配具体的完整的对象所需要的内存空间,其所分 ...