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的更多相关文章

  1. Educational Codeforces Round 36 (Rated for Div. 2) E. Physical Education Lessons

    提供两种思路 一种线段树区间更新 另一种用map维护连续的区间,也是题解的思路 第二种很难写(我太渣,看了别人的代码,发现自己写的太烦了) #include<iostream> #incl ...

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

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

  4. 【Educational Codeforces Round 36 D】 Almost Acyclic Graph

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 找到任意一个环. 然后枚举删掉其中的某一条边即可. (因为肯定要删掉这个环的,那么方法自然就是删掉其中的某一条边 (其它环,如果都包 ...

  5. 【Educational Codeforces Round 36 C】 Permute Digits

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] //从大到小枚举第i(1..len1)位 //剩余的数字从小到大排序. //看看组成的数字是不是小于等于b //如果是的话. //说 ...

  6. 【Educational Codeforces Round 36 B】Browser

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 分类在区间里面和左边.右边三种情况. 看看l的左边有没有标签.r的右边有没有标签. 就能做完了. [代码] #include < ...

  7. 【Educational Codeforces Round 36 A】 Garden

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举用哪一个桶就好 [代码] #include <bits/stdc++.h> using namespace std; ...

  8. Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题

    Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题 [Problem Description] ​ 总共两次询 ...

  9. [Educational Codeforces Round 16]E. Generate a String

    [Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...

随机推荐

  1. python_13 面向对象

    面向对象 类:把一类事物的相同特征和动作整合到一起就是类,类是一个抽象的概念 对象:就是基于类出而创建的一个具体的事物或实例(具体存在),其特征和动作整合到一起 面向对象设计:将一类具体事物的数据和动 ...

  2. 获取object的值

    class Program { static void Main(string[] args) { var data = Unite(); var name = data.GetType().GetP ...

  3. 解析如何实现微信唤醒默认浏览器下载app教程!

    前言 现如今微信对第三方app下载链接的拦截是越来越严格了,下载链接在微信中分享转发经常会被拦截,一旦被拦截用户就只能复制链接手动打开浏览器粘贴才能访问,如此给用户带来的体验台差,用户量无法有效地累积 ...

  4. 取消IDEA默认打开最近的项目(设置打开选择创建页面)

    Ctrl + Shift + s 打开设置界面 选择Appearance&Behavior 找到System Settings 将Reopen last project on startup ...

  5. 富文本编辑器 kindeditor

    下载 在页面中添加JS代码,用于初始化kindeditor <script type="text/javascript"> var editor; KindEditor ...

  6. ES6 Promise 用法转载

    Promise是一个构造函数,自己身上有all.reject.resolve这几个眼熟的方法,原型上有then.catch等同样很眼熟的方法. 那就new一个 var p = new Promise( ...

  7. layui xtree 实现一级节点单选 ,子节点复选

    在外部定义变量和方法 //定义变量 接收顶级节点的值 var topValue; // 获取顶级节点值的方法 function getParent(value) { var val = project ...

  8. spring AOP capbilities and goal

    Spring AOP 是用纯JAVA 实现的. 不需借助JAVA代码在编译处理阶段来实现. Spring 是在运行期实现的.AOP的实现可以在编译,加载,运行三个阶段来实现:Spring AOP 也不 ...

  9. react axios 配置

    1:package.json 添加        "proxy": "代理地址" 2  封装axios     创建server.js  添加 import a ...

  10. selenium使用技巧

    标签(空格分隔): selenium 我们进行selenium的时候,就是通过webdriver,对浏览器做一些操作的: webdriver,除了find操作,之外还有哪些方法和属性呢? 1.获取当前 ...