Skip to content

Commit ff3387c

Browse files
committed
🚀 10-Jan-2021
1 parent a4ffe47 commit ff3387c

11 files changed

+696
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
There are n digital panels placed in a straight line. Each panel can show any digit from 0 to 9. Initially, all panels show 0.
3+
4+
Every second, the digit shown by each panel increases by 1. In other words, at the end of every second, a panel that showed 9 would now show 0, a panel that showed 0 would now show 1, a panel that showed 1 would now show 2, and so on.
5+
6+
When a panel is paused, the digit displayed on the panel does not change in the subsequent seconds.
7+
8+
You must pause exactly one of these panels, at any second you wish. Then, the panels adjacent to it get paused one second later, the panels adjacent to those get paused 2 seconds later, and so on. In other words, if you pause panel x, panel y (for all valid y) would be paused exactly |x-y| seconds later.
9+
10+
For example, suppose there are 4 panels, and the 3-rd panel is paused when the digit 9 is on it.
11+
12+
The panel 1 pauses 2 seconds later, so it has the digit 1;
13+
the panel 2 pauses 1 second later, so it has the digit 0;
14+
the panel 4 pauses 1 second later, so it has the digit 0.
15+
The resulting 4-digit number is 1090. Note that this example is not optimal for n=4.
16+
17+
Once all panels have been paused, you write the digits displayed on them from left to right, to form an n digit number (it can consist of leading zeros). What is the largest possible number you can get? Initially, all panels show 0.
18+
19+
Input
20+
The first line of the input contains a single integer t (1=t=100) — the number of test cases. Each test case consists of a single line containing a single integer n (1=n=2·105).
21+
22+
It is guaranteed that the sum of n over all test cases does not exceed 2·105.
23+
24+
Output
25+
For each test case, print the largest number you can achieve, if you pause one panel optimally.
26+
27+
Example
28+
inputCopy
29+
2
30+
1
31+
2
32+
outputCopy
33+
9
34+
98
35+
Note
36+
In the first test case, it is optimal to pause the first panel when the number 9 is displayed on it.
37+
38+
In the second test case, it is optimal to pause the second panel when the number 8 is displayed on it.
39+
40+
41+
*/
42+
43+
44+
45+
46+
47+
#include<bits/stdc++.h>
48+
using namespace std;
49+
50+
51+
int main(){
52+
ios_base::sync_with_stdio(false);
53+
cin.tie(NULL);
54+
55+
int t;
56+
cin >> t;
57+
58+
while (t--) {
59+
int n;
60+
cin >> n;
61+
string res = "";
62+
63+
if (n >= 1) res += "9";
64+
if (n >= 2) res += "8";
65+
66+
int start = 9;
67+
68+
for (int i = 3; i <= n; i++) {
69+
res += start + '0';
70+
start++;
71+
start %= 10;
72+
}
73+
74+
cout << res << endl;
75+
}
76+
77+
78+
return 0;
79+
}
80+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
5+
int main(){
6+
ios_base::sync_with_stdio(false);
7+
cin.tie(NULL);
8+
9+
int t;
10+
cin >> t;
11+
12+
while (t--) {
13+
int n;
14+
cin >> n;
15+
16+
vector <int> v(n);
17+
for(int i = 0; i < n; i++) cin >> v[i];
18+
19+
int hill = 0, valley = 0;
20+
21+
for (int i = 1; i < n - 1; i++) {
22+
if(v[i] > v[i - 1] && v[i] > v[i + 1]) hill++;
23+
if(v[i] < v[i - 1] && v[i] < v[i + 1]) valley++;
24+
}
25+
cout << hill + valley << endl;
26+
}
27+
28+
return 0;
29+
}
30+
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all n dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirito's strength equals s.
3+
4+
If Kirito starts duelling with the i-th (1?=?i?=?n) dragon and Kirito's strength is not greater than the dragon's strength xi, then Kirito loses the duel and dies. But if Kirito's strength is greater than the dragon's strength, then he defeats the dragon and gets a bonus strength increase by yi.
5+
6+
Kirito can fight the dragons in any order. Determine whether he can move on to the next level of the game, that is, defeat all dragons without a single loss.
7+
8+
Input
9+
The first line contains two space-separated integers s and n (1?=?s?=?104, 1?=?n?=?103). Then n lines follow: the i-th line contains space-separated integers xi and yi (1?=?xi?=?104, 0?=?yi?=?104) — the i-th dragon's strength and the bonus for defeating it.
10+
11+
Output
12+
On a single line print "YES" (without the quotes), if Kirito can move on to the next level and print "NO" (without the quotes), if he can't.
13+
14+
Examples
15+
inputCopy
16+
2 2
17+
1 99
18+
100 0
19+
outputCopy
20+
YES
21+
inputCopy
22+
10 1
23+
100 100
24+
outputCopy
25+
NO
26+
Note
27+
In the first sample Kirito's strength initially equals 2. As the first dragon's strength is less than 2, Kirito can fight it and defeat it. After that he gets the bonus and his strength increases to 2?+?99?=?101. Now he can defeat the second dragon and move on to the next level.
28+
29+
In the second sample Kirito's strength is too small to defeat the only dragon and win.
30+
31+
32+
*/
33+
34+
35+
36+
#include<bits/stdc++.h>
37+
using namespace std;
38+
39+
bool comp(pair <int, int> &a, pair <int, int> &b) {
40+
if (a.first == b.second) return a.first < b.second;
41+
return a.first < b.second;
42+
}
43+
44+
int main(){
45+
ios_base::sync_with_stdio(false);
46+
cin.tie(NULL);
47+
48+
int s, n;
49+
cin >> s >> n;
50+
51+
52+
vector <pair <int, int> > xy;
53+
54+
int x, y;
55+
56+
for (int i = 0; i < n; i++) {
57+
cin >> x >> y;
58+
xy.push_back({x, y});
59+
}
60+
61+
sort(xy.begin(), xy.end()), comp;
62+
63+
bool win = true;
64+
65+
for (int i = 0; i < n; i++){
66+
if(s <= xy[i].first) {
67+
win = false;
68+
break;
69+
} else s += xy[i].second;
70+
}
71+
72+
if (win) cout << "YES";
73+
else cout << "NO";
74+
75+
76+
77+
return 0;
78+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money.
3+
4+
Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance.
5+
6+
Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift.
7+
8+
Input
9+
The single line contains integer n (10?=?|n|?=?109) — the state of Ilya's bank account.
10+
11+
Output
12+
In a single line print an integer — the maximum state of the bank account that Ilya can get.
13+
14+
Examples
15+
inputCopy
16+
2230
17+
outputCopy
18+
2230
19+
inputCopy
20+
-10
21+
outputCopy
22+
0
23+
inputCopy
24+
-100003
25+
outputCopy
26+
-10000
27+
Note
28+
In the first test sample Ilya doesn't profit from using the present.
29+
30+
In the second test sample you can delete digit 1 and get the state of the account equal to 0.
31+
*/
32+
33+
34+
35+
#include<bits/stdc++.h>
36+
using namespace std;
37+
38+
int main(){
39+
ios_base::sync_with_stdio(false);
40+
cin.tie(NULL);
41+
42+
int n;
43+
cin >> n;
44+
45+
if (n >=0) cout << n;
46+
else {
47+
n = abs(n);
48+
int last = n % 10;
49+
n /= 10;
50+
int mini = n;
51+
n /= 10;
52+
n = n * 10 + last;
53+
mini = min(mini, n);
54+
55+
cout << -mini;
56+
57+
}
58+
59+
return 0;
60+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
3+
4+
Devu has provided organizers a list of the songs and required time for singing them. He will sing n songs, ith song will take ti minutes exactly.
5+
6+
The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly.
7+
8+
People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest.
9+
10+
You as one of the organizers should make an optimal s?hedule for the event. For some reasons you must follow the conditions:
11+
12+
The duration of the event must be no more than d minutes;
13+
Devu must complete all his songs;
14+
With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible.
15+
If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event.
16+
17+
Input
18+
The first line contains two space separated integers n, d (1?=?n?=?100; 1?=?d?=?10000). The second line contains n space-separated integers: t1,?t2,?...,?tn (1?=?ti?=?100).
19+
20+
Output
21+
If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.
22+
23+
Examples
24+
inputCopy
25+
3 30
26+
2 2 1
27+
outputCopy
28+
5
29+
inputCopy
30+
3 20
31+
2 1 1
32+
outputCopy
33+
-1
34+
Note
35+
Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
36+
37+
First Churu cracks a joke in 5 minutes.
38+
Then Devu performs the first song for 2 minutes.
39+
Then Churu cracks 2 jokes in 10 minutes.
40+
Now Devu performs second song for 2 minutes.
41+
Then Churu cracks 2 jokes in 10 minutes.
42+
Now finally Devu will perform his last song in 1 minutes.
43+
Total time spent is 5?+?2?+?10?+?2?+?10?+?1?=?30 minutes.
44+
45+
Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1.
46+
*/
47+
48+
49+
50+
51+
#include<bits/stdc++.h>
52+
using namespace std;
53+
54+
55+
int main(){
56+
ios_base::sync_with_stdio(false);
57+
cin.tie(NULL);
58+
59+
int n, d;
60+
cin >> n >> d;
61+
62+
vector <int> v(n);
63+
for(int i = 0; i < n; i++) cin >> v[i];
64+
65+
int sum = 0;
66+
67+
for (int i = 0; i < n; i++) sum += v[i];
68+
69+
sum += 10 * (n - 1);
70+
71+
if(sum > d) cout << -1;
72+
else cout << (d - sum) / 5 + (n - 1) * 2;
73+
74+
}
75+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
3+
4+
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones.
5+
6+
Input
7+
The first line contains four space-separated x1,?y1,?x2,?y2 (?-?100?=?x1,?y1,?x2,?y2?=?100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct.
8+
9+
Output
10+
If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3,?y3,?x4,?y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them.
11+
12+
Note that x3,?y3,?x4,?y4 must be in the range (?-?1000?=?x3,?y3,?x4,?y4?=?1000).
13+
14+
Examples
15+
inputCopy
16+
0 0 0 1
17+
outputCopy
18+
1 0 1 1
19+
inputCopy
20+
0 0 1 1
21+
outputCopy
22+
0 1 1 0
23+
inputCopy
24+
0 0 1 2
25+
outputCopy
26+
-1
27+
28+
*/
29+
30+
31+
32+
#include<bits/stdc++.h>
33+
using namespace std;
34+
35+
int main(){
36+
ios_base::sync_with_stdio(false);
37+
cin.tie(NULL);
38+
39+
int x1, y1, x2, y2;
40+
cin >> x1 >> y1 >> x2 >> y2;
41+
42+
43+
if (x1 != x2 && y1 != y2 && abs(x1 - x2) != abs(y1 - y2))
44+
cout << -1;
45+
else if (x1 == x2) {
46+
cout << x1 + abs(y1 - y2) << " " << y1 << " " << x2 + abs(y1 - y2) << " " << y2;
47+
} else if (y1 == y2) {
48+
cout << x1 << " " << y1 + abs(x1 - x2) << " " << x2 << " " << y2 + abs(x1 - x2);
49+
} else cout << x1 << " " << y2 << " " << x2 << " " << y1;
50+
51+
52+
53+
return 0;
54+
}

0 commit comments

Comments
 (0)