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. mkdir npm

    mkdir -p 创建目录 没有就创建 有就用 npm init -y 不提示创建package.json 文件

  2. python学习Day5 几种数据类型的使用

    今日内容 数据类型分类: int | complex | float | str | bool | list | dict | tuple | set 3种数据类型的方法:(数字.字符串.列表 ) 可 ...

  3. CSS 背景图像 填充部分元素示例

    填充部分元素示例 为某个元素设置CSS规则background-image 属性,则可以做到部分元素有背景颜色. 下面的示例演示如何如何给段落元素加背景. <!DOCTYPE html> ...

  4. ORA-12541:TNS:无监听程序

    1.OracleServiceORCL确认已经在服务中启动 2.OracleOraDb11g_home1TNSListener确认已经在服务中启动 3.服务端listener.ora和tnsnames ...

  5. MATLA总结三

    1.将分数表示转换为小数表示: vpa( ******(表达式或者变量), n(小数点后几位)) 2.将一个式子中的变量带入具体的值: subs(  y, x, [2,3,4] ) 3.用工具箱确定阶 ...

  6. java.lang.OutOfMemoryError:GC overhead limit exceeded解决方法

    异常如下:Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded 一.解 ...

  7. 解题(ConflictPhoneNumber--冲突的电话号码)

    题目描述 移动推出的校内网短号和亲情网短号非常方便,但在某款新手机里却出现了尴尬的bug.例如,当通讯录中包含如下号码时:1.小王:6002.小李:4676543.小张:600010输入600时,手机 ...

  8. 一.javascript核心部分:1.词法结构

    本文作为个人学习笔记,一直也没有重视javascript的系统学习(javascript是最容易被人忽视的语言),我都是要用的时候百度一下查找下资料开始用,但没有系统的,学习,和整理过javascri ...

  9. 自己实现HashSet

    HashSet的实现相对比较简单.它强依赖于HashMap,包括底层数据实际上就是存储于HashMap,由于HashMap在哈希碰撞下,如果value值相同,那么将会覆盖该value,HashSet正 ...

  10. Selenium 实现nvsm查询和输出ksql语句

    测试环境:http://nvsm.cnki.net/kns/brief/result.aspx?dbprefix=SCDB 程序功能:对各个文献库的高级检索功能,输入检索条件做检索,提取加密的ksql ...