A.Air Conditioner
Sign-in question
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int x;
cin >> x;
if (x >= 30)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
B.Distance
Pay attention to the larger value
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
long long int n, d;
double x, y;
long int num = 0;
cin >> n >> d;
for (long int i = 1; i <= n; i++)
{
cin >> x >> y;
if (x * x + y * y <= d * d)
num++;
}
cout << num << endl;
}
C. Repsept
Give you a k. Find a length that contains only 7 output multiples from its multiples.
We can maintain a value, that is, the current value of the number modulo n composed of so many 7s. After adding a 7 at the end, it becomes 10x+7, so the modulus is also multiplied by 10 plus 7.
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
long long int k;
cin >> k;
int ans = 1;
for (int mod = 7; mod % k; mod = (mod * 10 + 7) % k)
{
if (++ans > k)
{
ans = -1;
break;
}
}
cout << ans << endl;
}
D. Old altar
There are n stones in a row. There are two types of stones, one is R and the other is W. Two operations can be performed: exchange any two stones and change the type of one. Ask after at least a few operations, there is no situation where the left next to the R pebble is W
In the final case, the left side is all R and the right side is all W.
So we can calculate the number of W as ans, and then get the number of characters whose ans bit is not W at the end, and then exchange each with the previous one to achieve the optimal situation
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
char s[200005];
long int n;
cin >> n;
long int ans = 0;
for (int i = 0; i <n; i++)
{
cin >> s[i];
if (s[i] == 'W')
ans++;
}
long long cnt = 0;
for (int i = n - ans; i < n; i++)
{
if (s[i] != 'W')
cnt++;
}
cout << cnt << endl;
}
E.Logs
There are n pieces of wood, and each piece of wood has its own length. You can cut k times to make the longest and shortest of the cut pieces. Ask how long the shortest is (the decimals are rounded up).
We can think of it this way, considering the number of times that each block must be split at least so that the new block produced does not contain a block larger than mid. Can the maximum value of the block be finally not greater than mid and the number of splits not more than k times? . Too many times will increase the value of mid, and too few will decrease the distance of mid, and constantly update the value of mid to maximize it. (Approximate multiple times by dichotomy)
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
long int n;
long int a[200005];
long int k;
inline int log_number(int log, int mid)
{
if (log % mid == 0)
return log / mid;
else
return log / mid+1;
}
bool check(int len)
{
int ans = 0;
for (int i = 1; i <= n; i++)
{
ans += log_number(a[i], len)-1;
}
if (ans <= k)
return true;
else
return false;
}
int main()
{
cin >> n >> k;
for (int i = 1; i <=n; i++)
{
cin >> a[i];
}
int l = 1, r = 1e9;
while (r - l > 1)
{
int mid = (l + r) / 2;
if (check(mid))
r = mid;
else l = mid;
}
cout << (check(l) ? l : r) << endl;
}
F.Range Set Query
A sequence of length n, there are several different numbers in the interval [L,R] when asked each time
Tree array, Luogu original question, title