codeforces AIM Tech Round 3 (Div. 2) (A~D)
Kolya is going to make fresh orange juice. He has?n?oranges of sizes?a1,?a2,?...,?an. Kolya will put them in the juicer in the fixed order, starting with orange of size?a1, then orange of size?a2?and so on. To be put in the juicer the orange must have size not exceeding?b, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.
The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than?d. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section?
InputThe first line of the input contains three integers?n,?b?and?d?(1?≤?n?≤?100?000,?1?≤?b?≤?d?≤?1?000?000)?— the number of oranges, the maximum size of the orange that fits in the juicer and the value?d, which determines the condition when the waste section should be emptied.
The second line contains?n?integers?a1,?a2,?...,?an?(1?≤?ai?≤?1?000?000)?— sizes of the oranges listed in the order Kolya is going to try to put them in the juicer.
OutputPrint one integer?— the number of times Kolya will have to empty the waste section.
Examples input 2 7 10 5 6 output 1 input 1 5 10 7 output 0 input 3 10 10 5 7 7 output 1 input 1 1 1 1 output 0 NoteIn the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all.
題解:給你n個橙,要選小于等于b的橙做成果汁,如果放進果汁機的橙總和大于d,就要浪費一次。問你把這些橙全部做成果汁后,浪費了多少次。模擬一下就可以了。
代碼:
#pragma comment(linker, "/STACK:102400000,102400000") //#include<bits/stdc++.h> #include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> #include<cstring> #include<vector> #include<map> #include<cmath> #include<queue> #include<set> #include<stack> #include <utility> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; #define mst(a) memset(a, 0, sizeof(a)) #define M_P(x,y) make_pair(x,y) #define rep(i,j,k) for (int i = j; i <= k; i++) #define per(i,j,k) for (int i = j; i >= k; i--) #define lson x << 1, l, mid #define rson x << 1 | 1, mid + 1, r const int lowbit(int x) { return x&-x; } const double eps = 1e-8; const int INF = 1e9+7; const ll inf =(1LL<<62) ; const int MOD = 1e9 + 7; const ll mod = (1LL<<32); const int N = 110; const int M=100010; const int maxn=1001; template <class T1, class T2>inline void getmax(T1 &a, T2 b) {if (b>a)a = b;} template <class T1, class T2>inline void getmin(T1 &a, T2 b) {if (b<a)a = b;} int read(){ int v = 0, f = 1;char c =getchar(); while( c < 48 || 57 < c ){if(c=='-') f = -1;c = getchar();} while(48 <= c && c <= 57) v = v*10+c-48, c = getchar(); return v*f;} int a; int main() {ll n,b,d;cin>>n>>b>>d;ll sum=0;ll ans=0;for(int i=0;i<n;i++){cin>>a;if(a<=b)sum+=a;if(sum>d)sum=0,ans++; }cout<<ans;return 0; } B. Checkpoints time limit per test 1 second memory limit per test 256 megabytes input standard input output standard outputVasya takes part in the orienteering competition. There are?n?checkpoints located along the line at coordinates?x1,?x2,?...,?xn. Vasya starts at the point with coordinate?a. His goal is to visit at least?n?-?1?checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary order.
Vasya wants to pick such checkpoints and the order of visiting them that the total distance travelled is minimized. He asks you to calculate this minimum possible value.
InputThe first line of the input contains two integers?n?and?a?(1?≤?n?≤?100?000,??-?1?000?000?≤?a?≤?1?000?000)?— the number of checkpoints and Vasya's starting position respectively.
The second line contains?n?integers?x1,?x2,?...,?xn?(?-?1?000?000?≤?xi?≤?1?000?000)?— coordinates of the checkpoints.
OutputPrint one integer?— the minimum distance Vasya has to travel in order to visit at least?n?-?1?checkpoint.
Examples input 3 10 1 7 12 output 7 input 2 0 11 -10 output 10 input 5 0 0 0 1000 0 0 output 0 NoteIn the first sample Vasya has to visit at least two checkpoints. The optimal way to achieve this is the walk to the third checkpoints (distance is?12?-?10?=?2) and then proceed to the second one (distance is?12?-?7?=?5). The total distance is equal to?2?+?5?=?7.
In the second sample it's enough to visit only one checkpoint so Vasya should just walk to the point??-?10.
題意:給你n個點,要經過n-1個點才算完成比賽,問完成比賽的最小路程。
題解:因為要經過n-1個點,所以只要貪心一下a附近n-1個點就可以啦。
比如下面這圖:a附近的X1到Xn-1。
還有的X0到Xn-2也一樣。
再選其中路程最短就可以了。
代碼:
#pragma comment(linker, "/STACK:102400000,102400000") //#include<bits/stdc++.h> #include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> #include<cstring> #include<vector> #include<map> #include<cmath> #include<queue> #include<set> #include<stack> #include <utility> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; #define mst(a) memset(a, 0, sizeof(a)) #define M_P(x,y) make_pair(x,y) #define rep(i,j,k) for (int i = j; i <= k; i++) #define per(i,j,k) for (int i = j; i >= k; i--) #define lson x << 1, l, mid #define rson x << 1 | 1, mid + 1, r const int lowbit(int x) { return x&-x; } const double eps = 1e-8; const int INF = 1e9+7; const ll inf =(1LL<<62) ; const int MOD = 1e9 + 7; const ll mod = (1LL<<32); const int N = 110; const int M=100010; const int maxn=1001; template <class T1, class T2>inline void getmax(T1 &a, T2 b) {if (b>a)a = b;} template <class T1, class T2>inline void getmin(T1 &a, T2 b) {if (b<a)a = b;} int read(){ int v = 0, f = 1;char c =getchar(); while( c < 48 || 57 < c ){if(c=='-') f = -1;c = getchar();} while(48 <= c && c <= 57) v = v*10+c-48, c = getchar(); return v*f;} ll num[200010]; int main() {ll n,a;cin>>n>>a;for(int i=0;i<n;i++)cin>>num[i];sort(num,num+n);if(n==1){cout<<0;return 0;}ll x=min(abs(num[0]-a),abs(num[n-2]-a))+num[n-2]-num[0];ll y=min(abs(num[1]-a),abs(num[n-1]-a))+num[n-1]-num[1];cout<<min(x,y);return 0; } C. Letters Cyclic Shift time limit per test 1 second memory limit per test 256 megabytes input standard input output standard outputYou are given a non-empty string?s?consisting of lowercase English letters. You have to pick?exactly one non-empty substring?of?sand shift all its letters 'z'??'y'??'x'??'b'??'a'??'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.
What is the lexicographically minimum string that can be obtained from?s?by performing this shift exactly once?
InputThe only line of the input contains the string?s?(1?≤?|s|?≤?100?000) consisting of lowercase English letters.
OutputPrint the lexicographically minimum string that can be obtained from?s?by shifting letters of exactly one non-empty substring.
Examples input codeforces output bncdenqbdr input abacaba output aaacaba Note:String?s?is lexicographically smaller than some other string?t?of the same length if there exists some?1?≤?i?≤?|s|, such thats1?=?t1,?s2?=?t2,?...,?si?-?1?=?ti?-?1, and?si?<?ti.題解:?如果不是全部是a,就找到第一個不是a的子串shift。如果全部是a,最后一個a就變成z。
代碼: #pragma comment(linker, "/STACK:102400000,102400000") //#include<bits/stdc++.h> #include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> #include<cstring> #include<vector> #include<map> #include<cmath> #include<queue> #include<set> #include<stack> #include <utility> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; #define mst(a) memset(a, 0, sizeof(a)) #define M_P(x,y) make_pair(x,y) #define rep(i,j,k) for (int i = j; i <= k; i++) #define per(i,j,k) for (int i = j; i >= k; i--) #define lson x << 1, l, mid #define rson x << 1 | 1, mid + 1, r const int lowbit(int x) { return x&-x; } const double eps = 1e-8; const int INF = 1e9+7; const ll inf =(1LL<<62) ; const int MOD = 1e9 + 7; const ll mod = (1LL<<32); const int N = 110; const int M=100010; const int maxn=1001; template <class T1, class T2>inline void getmax(T1 &a, T2 b) {if (b>a)a = b;} template <class T1, class T2>inline void getmin(T1 &a, T2 b) {if (b<a)a = b;} int read(){ int v = 0, f = 1;char c =getchar(); while( c < 48 || 57 < c ){if(c=='-') f = -1;c = getchar();} while(48 <= c && c <= 57) v = v*10+c-48, c = getchar(); return v*f;}int main() {string s;cin>>s;int i=0;while(i<s.size() && s[i]=='a')i++;//cout<<"i="<<i<<endl;if(i==s.size()) s[s.size()-1]='z';for(;i<s.size();i++){if(s[i]=='a')break;s[i]=s[i]-1;}cout<<s;return 0; } D. Recover the String time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output
For each string?s?consisting of characters '0' and '1' one can define four integers?a00,?a01,?a10?and?a11, where?axy?is the number ofsubsequences?of length?2?of the string?s?equal to the sequence?{x,?y}.
In these problem you are given four integers?a00,?a01,?a10,?a11?and have to find any non-empty string?s?that matches them, or determine that there is no such string. One can prove that if at least one answer exists, there exists an answer of length no more than1?000?000.
InputThe only line of the input contains four non-negative integers?a00,?a01,?a10?and?a11. Each of them doesn't exceed?109.
OutputIf there exists a non-empty string that matches four integers from the input, print it in the only line of the output. Otherwise, print "Impossible". The length of your answer must not exceed?1?000?000.
Examples input 1 2 3 4 output Impossible input 1 2 2 1 output 0110 題意:給你00,01,10,11這四個序列的個數。然后要你構造出合法的01序列。不存在合法的01序列就輸出Impossible。 例如:0110有1個00,2個01,2個10,1個11。 題解:因為n*(n-1)=2*a00和m*(m-1)=2*a11和a01+a10=n*m。 所以可以先計算出0和1的數量,接下來先去構造a10,再構造a01就好了。構造題。代碼: #pragma comment(linker, "/STACK:102400000,102400000") //#include<bits/stdc++.h> #include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> #include<cstring> #include<vector> #include<map> #include<cmath> #include<queue> #include<set> #include<stack> #include <utility> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; #define mst(a) memset(a, 0, sizeof(a)) #define M_P(x,y) make_pair(x,y) #define rep(i,j,k) for (int i = j; i <= k; i++) #define per(i,j,k) for (int i = j; i >= k; i--) #define lson x << 1, l, mid #define rson x << 1 | 1, mid + 1, r const int lowbit(int x) { return x&-x; } const double eps = 1e-8; const int INF = 1e9+7; const ll inf =(1LL<<62) ; const int MOD = 1e9 + 7; const ll mod = (1LL<<32); const int N = 110; const int M=100010; const int maxn=1001; template <class T1, class T2>inline void getmax(T1 &a, T2 b) {if (b>a)a = b;} template <class T1, class T2>inline void getmin(T1 &a, T2 b) {if (b<a)a = b;} int read(){ int v = 0, f = 1;char c =getchar(); while( c < 48 || 57 < c ){if(c=='-') f = -1;c = getchar();} while(48 <= c && c <= 57) v = v*10+c-48, c = getchar(); return v*f;}ll a00,a01,a10,a11; int main() {ll n,m;cin>>a00>>a01>>a10>>a11;if(a00==0&&a01==0&&a10==0&&a11==0){cout<<0; return 0;}n=(1+(int)( sqrt(1+8*a00) ))/2; //n:0的個數 m=(1+(int)( sqrt(1+8*a11) ))/2; //m:1的個數 if(a01==0&&a10==0){if(a00==0) n=0;else m=0;}if(n*(n-1)!=2*a00||m*(m-1)!=2*a11||a01+a10!=n*m){cout<<"Impossible";return 0;}while(n+m){if(a01>=m){cout<<0;a01-=m;--n;}else{cout<<1;a10-=n;--m;}}return 0; }
總結
以上是生活随笔為你收集整理的codeforces AIM Tech Round 3 (Div. 2) (A~D)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 再迎顶尖科学家,百度研究院为何如此吸引大
- 下一篇: AI 趋势