A. Garden
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Luba thinks about watering her garden. The garden can be represented as a segment of length k. Luba has got n buckets, the i-th bucket allows her to water some continuous subsegment of garden of length exactly ai each hour. Luba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden.

Luba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegment of length ai if she chooses the i-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden. It is guaranteed that Luba can always choose a bucket so it is possible water the garden.

See the examples for better understanding.

Input

The first line of input contains two integer numbers n and k (1 ≤ n, k ≤ 100) — the number of buckets and the length of the garden, respectively.

The second line of input contains n integer numbers ai (1 ≤ ai ≤ 100) — the length of the segment that can be watered by the i-th bucket in one hour.

It is guaranteed that there is at least one bucket such that it is possible to water the garden in integer number of hours using only this bucket.

Output

Print one integer number — the minimum number of hours required to water the garden.

Examples
input

Copy
  1. 3 6
    2 3 5
output
  1. 2
input

Copy
  1. 6 7
    1 2 3 4 5 6
output
  1. 7
Note

In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden.

In the second test we can choose only the bucket that allows us to water the segment of length 1.

k能整除当前数的时候,找出那个最大的倍数

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int a[];
  4. int main()
  5. {
  6. int n,k,f=;
  7. cin>>n>>k;
  8. for(int i=,x;i<n;i++)
  9. {
  10. cin>>x;
  11. if(k%x==&&x>f)f=x;
  12. }
  13. cout<<k/f;
  14. return ;
  15. }
B. Browser
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Luba is surfing the Internet. She currently has n opened tabs in her browser, indexed from 1 to n from left to right. The mouse cursor is currently located at the pos-th tab. Luba needs to use the tabs with indices from l to r (inclusive) for her studies, and she wants to close all the tabs that don't belong to this segment as fast as possible.

Each second Luba can either try moving the cursor to the left or to the right (if the cursor is currently at the tab i, then she can move it to the tab max(i - 1, a) or to the tab min(i + 1, b)) or try closing all the tabs to the left or to the right of the cursor (if the cursor is currently at the tab i, she can close all the tabs with indices from segment [a, i - 1] or from segment [i + 1, b]). In the aforementioned expressions a and b denote the minimum and maximum index of an unclosed tab, respectively. For example, if there were 7 tabs initially and tabs 1, 2 and 7are closed, then a = 3, b = 6.

What is the minimum number of seconds Luba has to spend in order to leave only the tabs with initial indices from l to r inclusiveopened?

Input

The only line of input contains four integer numbers nposlr (1 ≤ n ≤ 100, 1 ≤ pos ≤ n, 1 ≤ l ≤ r ≤ n) — the number of the tabs, the cursor position and the segment which Luba needs to leave opened.

Output

Print one integer equal to the minimum number of seconds required to close all the tabs outside the segment [l, r].

Examples
input

Copy
  1. 6 3 2 4
output
  1. 5
input

Copy
  1. 6 3 1 3
output
  1. 1
input

Copy
  1. 5 2 1 5
output
  1. 0
Note

In the first test Luba can do the following operations: shift the mouse cursor to the tab 2, close all the tabs to the left of it, shift the mouse cursor to the tab 3, then to the tab 4, and then close all the tabs to the right of it.

In the second test she only needs to close all the tabs to the right of the current position of the cursor.

In the third test Luba doesn't need to do anything.

给你n pos l r,分别代表几个网页,你现在在第几个网页,你需要关闭l左边的网页,和r右边的网页,你可以移到一个网页把之前或之后的关闭,问你最少走几步

那么我枚举到l r的距离即可分别选择先向左还是先向右

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int n,pos,l,r,f=;
  6. cin>>n>>pos>>l>>r;
  7. if(l==&&r==n)
  8. f=;
  9. else if(l==)
  10. f=abs(pos-r)+;
  11. else if(r==n)
  12. f=abs(pos-l)+;
  13. else
  14. {
  15. if(pos<l)
  16. f=r-pos+;
  17. else if(pos>r)
  18. f=pos-l+;
  19. else
  20. f=min(pos-l,r-pos)+r-l+;
  21. }
  22. cout<<f;
  23. return ;
  24. }
C. Permute Digits
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0.

It is allowed to leave a as it is.

Input

The first line contains integer a (1 ≤ a ≤ 1018). The second line contains integer b (1 ≤ b ≤ 1018). Numbers don't have leading zeroes. It is guaranteed that answer exists.

Output

Print the maximum possible number that is a permutation of digits of a and is not greater than b. The answer can't have any leading zeroes. It is guaranteed that the answer exists.

The number in the output should have exactly the same length as number a. It should be a permutation of digits of a.

Examples
input

Copy
  1. 123
    222
output
  1. 213
input

Copy
  1. 3921
    10000
output
  1. 9321
input

Copy
  1. 4940
    5000
output
  1. 4940

给你一个数x和n,你可以把m随意更改顺序构造不大于n的最大的数

当时我错的条件就是等于

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. string s,c;
  4. int cmp(char x,char y)
  5. {
  6. return x>y;
  7. }
  8. long long ans=,b;
  9. void dfs(int f,long long x,string a)
  10. {
  11. if(c[f])
  12. {
  13. long long x1=x;
  14. string bb=a;
  15. int mi=,mif=-,maf=-;
  16. for(int i=; a[i]; i++)
  17. if(a[i]==c[f])maf=i;
  18. else if(a[i]<c[f]&&a[i]>=mi)mif=i,mi=a[i];
  19. if(mif!=-)
  20. {
  21. if(f==&&a[mif]=='')
  22. {
  23.  
  24. }
  25. else
  26. {
  27. x=x*+a[mif]-'';
  28. a[mif]=;
  29. sort(a.begin(),a.end(),cmp);
  30. for(int i=;i<(int)a.size()-f-;i++)
  31. x=x*+a[i]-'';
  32. if(x<=b)ans=max(ans,x);
  33. }
  34. }
  35. if(maf!=-)
  36. {
  37. x1=x1*+bb[maf]-'';
  38. bb[maf]=;
  39. dfs(f+,x1,bb);
  40. }
  41. }
  42. else
  43. {
  44. if(x<=b)ans=max(ans,x);
  45. return;
  46. }
  47. }
  48. int main()
  49. {
  50. long long a;
  51. cin>>a>>b;
  52. stringstream ss;
  53. ss<<a;
  54. s=ss.str();
  55. stringstream sss;
  56. sss<<b;
  57. c=sss.str();
  58. if(s.size()<c.size())
  59. {
  60. sort(s.begin(),s.end(),cmp);
  61. cout<<s;
  62. }
  63. else
  64. {
  65. dfs(,,s);
  66. cout<<ans;
  67. }
  68. return ;
  69. }

Educational Codeforces Round 36 (Rated for Div. 2)的更多相关文章

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

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

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

  4. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  5. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  6. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

  7. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

  8. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  9. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...

随机推荐

  1. C# 向服务器上传文件(客服端winform、服务端web)

    转载 首先写客服端,winform模拟一个post提交: /// <summary> /// 将本地文件上传到指定的服务器(HttpWebRequest方法) /// </summa ...

  2. Windows7(x86) xampp php5.5 imagick install

    I hate windows. 1. 下载安装 ImageMagick, 选择合适您电脑的版本,我下载的是: ImageMagick-6.8.9-1-Q16-x86-dll.exe http://ww ...

  3. java面试题(杨晓峰)---第六讲谈谈动态代理是基于什么原理?

    我在编译时不知道,而在运行时知道,那么肯定在运行时给了提示,这个提示就是额外功.好处是可以重复利用相同代码. 代理模式:通过代理静默的解决一些与业务无关的问题,例如远程,安全,事物,日志,资源关闭,. ...

  4. Failed to load property source from location 'classpath:/applica)

    : 1.注释错误(application.yml用的是#注释) 2.缩进采用tab而不是空格引起的(不同配置之间也不能有tab出现,否则会报错) 3.冒号后面必须有空格否则会报错

  5. springboot(二十一)-集成memcached

    Memcached 介绍 Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站 ...

  6. FTP服务器建立windows与Linux的文件共享与读写操作

    centos7搭建vsftpd  2018-11-15 我们有时想要windows与Linux互传文件,就要用到vsftpd了.它仅仅在windows上面操作,就可以实现与Linux的通信,详情如下: ...

  7. mac层到ath9k层,ath9k层到硬件层

    如上图,整个 mac 层分成两个部分——UMAC 和 LMAC.LMAC 分成 MAC 下半部分和硬件抽象层. 硬件抽象层和ath9k层的连接 在hw.h中的函数struct ath_hw_ops() ...

  8. GIT在团队中的最佳实践

    我们已经从SVN 切换到Git很多年了,现在几乎所有的项目都在使用Github管理, 本篇文章讲一下为什么使用Git, 以及如何在团队中正确使用. Git的优点 Git的优点很多,但是这里只列出我认为 ...

  9. 监测UITextField的变化

    监测UITextField的变化可以为UIControlEventEditingChanged事件添加target. 我们有时候会需要用到这个需求:输入框输入文本超过xx长度,不再允许输入其他内容! ...

  10. Linux菜鸟起飞之路【五】权限管理(一)

    一.与用户相关的几个文件 1./etc/passwd 储存用户名,格式为 用户名:密码(用密码代位符X代替):UID:GID:用户描述信息:家目录:shell 用户名(login_name):是代表用 ...