Educational Codeforces Round 36 (Rated for Div. 2)
1 second
256 megabytes
standard input
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.
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.
Print one integer number — the minimum number of hours required to water the garden.
- 3 6
2 3 5
- 2
- 6 7
1 2 3 4 5 6
- 7
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能整除当前数的时候,找出那个最大的倍数
- #include <bits/stdc++.h>
- using namespace std;
- int a[];
- int main()
- {
- int n,k,f=;
- cin>>n>>k;
- for(int i=,x;i<n;i++)
- {
- cin>>x;
- if(k%x==&&x>f)f=x;
- }
- cout<<k/f;
- return ;
- }
1 second
256 megabytes
standard input
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?
The only line of input contains four integer numbers n, pos, l, r (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.
Print one integer equal to the minimum number of seconds required to close all the tabs outside the segment [l, r].
- 6 3 2 4
- 5
- 6 3 1 3
- 1
- 5 2 1 5
- 0
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的距离即可分别选择先向左还是先向右
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int n,pos,l,r,f=;
- cin>>n>>pos>>l>>r;
- if(l==&&r==n)
- f=;
- else if(l==)
- f=abs(pos-r)+;
- else if(r==n)
- f=abs(pos-l)+;
- else
- {
- if(pos<l)
- f=r-pos+;
- else if(pos>r)
- f=pos-l+;
- else
- f=min(pos-l,r-pos)+r-l+;
- }
- cout<<f;
- return ;
- }
1 second
256 megabytes
standard input
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.
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.
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.
- 123
222
- 213
- 3921
10000
- 9321
- 4940
5000
- 4940
给你一个数x和n,你可以把m随意更改顺序构造不大于n的最大的数
当时我错的条件就是等于
- #include <bits/stdc++.h>
- using namespace std;
- string s,c;
- int cmp(char x,char y)
- {
- return x>y;
- }
- long long ans=,b;
- void dfs(int f,long long x,string a)
- {
- if(c[f])
- {
- long long x1=x;
- string bb=a;
- int mi=,mif=-,maf=-;
- for(int i=; a[i]; i++)
- if(a[i]==c[f])maf=i;
- else if(a[i]<c[f]&&a[i]>=mi)mif=i,mi=a[i];
- if(mif!=-)
- {
- if(f==&&a[mif]=='')
- {
- }
- else
- {
- x=x*+a[mif]-'';
- a[mif]=;
- sort(a.begin(),a.end(),cmp);
- for(int i=;i<(int)a.size()-f-;i++)
- x=x*+a[i]-'';
- if(x<=b)ans=max(ans,x);
- }
- }
- if(maf!=-)
- {
- x1=x1*+bb[maf]-'';
- bb[maf]=;
- dfs(f+,x1,bb);
- }
- }
- else
- {
- if(x<=b)ans=max(ans,x);
- return;
- }
- }
- int main()
- {
- long long a;
- cin>>a>>b;
- stringstream ss;
- ss<<a;
- s=ss.str();
- stringstream sss;
- sss<<b;
- c=sss.str();
- if(s.size()<c.size())
- {
- sort(s.begin(),s.end(),cmp);
- cout<<s;
- }
- else
- {
- dfs(,,s);
- cout<<ans;
- }
- return ;
- }
Educational Codeforces Round 36 (Rated for Div. 2)的更多相关文章
- Educational Codeforces Round 36 (Rated for Div. 2) E. Physical Education Lessons
提供两种思路 一种线段树区间更新 另一种用map维护连续的区间,也是题解的思路 第二种很难写(我太渣,看了别人的代码,发现自己写的太烦了) #include<iostream> #incl ...
- 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 71 (Rated for Div. 2)-E. XOR Guessing-交互题
Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题 [Problem Description] 总共两次询 ...
- 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 ...
- 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 ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- 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 ...
- 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 ...
随机推荐
- Android笔记--View绘制流程源码分析(一)
Android笔记--View绘制流程源码分析 View绘制之前框架流程分析 View绘制的分析始终是离不开Activity及其内部的Window的.在Activity的源码启动流程中,一并包含 着A ...
- iOS Programming Autorotation, Popover Controllers, and Modal View Controllers
iOS Programming Autorotation, Popover Controllers, and Modal View Controllers 自动旋转,Popover 控制器,Moda ...
- 《剑指offer》39题—数组中出现次数超过一半的数字
题目描述 数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字.例如输入一个长度为9的数组{1,2,3,2,2,2,5,4,2}.由于数字2在数组中出现了5次,超过数组长度的一半,因此输出2. ...
- JWT (JSON WEB Token)正确使用场景
https://www.jianshu.com/p/af8360b83a9f 讲真,别再使用JWT了! ThoughtWorks中国 2017.08.16 08:51* 字数 2882 阅读 7154 ...
- Mac brew 安装amp环境
|首先加入Homebrew官方的几个软件源 $ brew tap homebrew/dupes $ brew tap homebrew/versions $ brew tap homebrew/php ...
- (68)zabbix windows性能计数器使用详解
概述 windows下的性能计数器让zabbix监控更加轻松,直接获取性能计数器的数值即可完成windows监控.性能计数器如下: 1 perf_counter["\Processor( ...
- 示例vue 的keep-alive缓存功能的实现
本篇文章主要介绍了vue 的keep-alive缓存功能的实现,写的十分的全面细致,具有一定的参考价值,对此有需要的朋友可以参考学习下.如有不足之处,欢迎批评指正. Vue 实现组件信息的缓存 当我们 ...
- pyqt设计
pyqt是python设计GUI的第三方包 作为一个小白,我觉得这篇博客贼好,我就是按照这个博客写的. 这个博客一共分5步,每一步都特别详细. pyqt 打包exe时遇到的问题(我的python环境是 ...
- Python9-hashilib模块-day28(大年初三)
__getitem__\__setitem__\__delitem__ class Foo: def __init__(self,name,age,sex): self.name = name sel ...
- 虚拟化技术xen,kvm,qemu区别
虚拟化类型 全虚拟化(Full Virtualization) 全虚拟化也成为原始虚拟化技术,该模型使用虚拟机协调guest操作系统和原始硬件,VMM在guest操作系统和裸硬件之间用于工作协调,一些 ...