Game case
Anger cut \ (A, B, C, D \) , behind \ (E, F \) two technical questions will not do too much food, do not know when to fill up.
Tournament Summary
Facts have proved that:
Before the game drink beverage bottle fatigue have a significant effect on the player in the game.
The game was played to accompany a significant effect on AC topic.
Seriously:
- Do not be nervous, do not be too relaxed. Which is conducive to play a real level.
Here began Loved The explanations of it.
A
Entry title
Enumeration can find the nearest available floor. With \ (the STL \) inside map
determines whether a floor is available to use.
Code
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
inline int read() {
int x=0,f=1; char ch=getchar();
while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
while(ch>='0'&&ch<='9') { x=(x<<3)+(x<<1)+(ch^48); ch=getchar(); }
return x * f;
}
int n,S,K,ans;
void work() {
map<int,bool> vis;
n = read(), S = read(), K = read(); ans = INF;
for(int i=1,x;i<=K;++i) {
x = read(); vis[x] = 1;
}
for(int j=0;S+j<=n||S-j>=1;++j) {
if(S+j <= n && !vis[S+j]) {
ans = j; break;
}
if(S-j >= 1 && !vis[S-j]) {
ans = j; break;
}
}
printf("%d\n",ans);
}
int main()
{
int T = read();
while(T--) work();
return 0;
}
B
Greedy title
Assuming that the optimal strategy is: a person got it wrong every election, the current remaining \ (s \) income when the person is \ (\ FRAC {1} {S} \) , the answer is \ (\ sum_ {i = 1 n-^} \ FRAC. 1} {} {I \) .
Use mathematical induction to prove the correctness of this conjecture (in fact, you can manually simulate + emotional understanding qwq)
Proof:
For the \ (the n-1 = \) , the answer is \ (\ FRAC {1} {1} \) , is clearly established.
For any \ (k, k> 1 \) , assumptions \ (k-1 \) was established, let's prove \ (k \) is also true.
\ (k-1 \) maximum benefit when the \ (\ sum_ {i = 1
} ^ {k-1} \ frac {1} {i} \) if \ (K \) turn does not take \ (\ FRAC {K}. 1} {\) , but rather, any positive integer \ (R & lt, R & lt>. 1, \ R & lt FRAC {} {} K \) , the answer is \ (\ frac {r} { k} + \ sum_ } ^ = I. 1 {KR} {\) , however, \ (\ sum_ KR + = {I}. 1 ^ K \ FRAC. 1 {{}} I> \ R & lt FRAC {} {} K \) (as can be the right side is written \ (\ sum_ = {I}. 1 ^ R & lt \ FRAC. 1 {{}} K \) , and the formula is the same number of entries, but each of the left and the formula are each greater than or equal to the right of )
so for \ (k, \ frac {1 } {k} + \ sum_ {i = 1} ^ {k-1} \ frac {1} {i} \) is the maximum answer.
(I actually proved somewhat cumbersome)
Code
#include<bits/stdc++.h>
using namespace std;
inline int read() {
int x=0,f=1; char ch=getchar();
while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
while(ch>='0'&&ch<='9') { x=(x<<3)+(x<<1)+(ch^48); ch=getchar(); }
return x * f;
}
int n;
double sum=0;
int main(){
n = read();
for(double i=1;i<=n;i++){
sum += 1 / i;
}
printf("%.10f\n",sum);
}
C
Simulation title
The maze is divided into two parts, upper part \ (X \) lattice denoted \ (m_Low {0, X} \) , the lower part of \ (X \) th denoted \ (m_ {1, x} \ ) .
Can be found if \ (m_ {0, x} \) lava, \ (m_Low {. 1, X-. 1}, m_Low {. 1, X}, m_Low {. 1, X +. 1} \) can not lava, or outputsNo
Then there is the meaning of the questions by simulation.
Code
#include<bits/stdc++.h>
using namespace std;
inline int read() {
int x=0,f=1; char ch=getchar();
while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
while(ch>='0'&&ch<='9') { x=(x<<3)+(x<<1)+(ch^48); ch=getchar(); }
return x * f;
}
const int N = 2e5+7;
int n,q,cnt;
int vis[N],ctr[N],sto[N];
int main()
{
n = read(), q = read();
for(int i=1;i<=q;++i) {
int x = read(), y = read();
if(x == 1) {
if(vis[y] == 0) {
vis[y] = 1;
for(int j=-1;j<=1;++j)
if(y+j>=1 && y+j<=n) {
if(ctr[y+j] == 0 && sto[y+j]==1) {
++cnt;
}
ctr[y+j]++;
}
} else {
vis[y] = 0;
for(int j=-1;j<=1;++j)
if(y+j>=1 && y+j<=n) {
if(ctr[y+j] == 1 && sto[y+j]==1)
--cnt;
ctr[y+j]--;
}
}
} else {
if(sto[y] == 0) {
sto[y] = 1;
if(ctr[y]) ++cnt;
} else {
sto[y] = 0;
if(ctr[y]) --cnt;
}
}
if(!cnt) puts("Yes");
else puts("No");
}
return 0;
}
D
Violence enumeration title
There is a technique, see \ (a_x, a_y> = 2 \) , which inspired us to count no more than \ (\ log_2 t \) th (which is counted on a topic learned skills, look at the subject data qwq) .
There is also a distance nature, as is the Manhattan distance, we can get a point away from \ (i \) point reach the first \ (i + 1 \) point or come \ (i-1 \) point, and do not turn back.
So that our algorithm is ready to come out, and went from the starting point enumeration \ (P \) , and then enumerate from the point \ (P \) go up, go down two routes, statistics can go up a few steps.
(I think this question codes force a little big qwq)
update: Wrong Answer on test 125
Code
#include<bits/stdc++.h>
#define int long long
#define INF 0x3f3f3f3f3f3f3f3f
using namespace std;
inline int read() {
int x=0,f=1; char ch=getchar();
while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
while(ch>='0'&&ch<='9') { x=(x<<3)+(x<<1)+(ch^48); ch=getchar(); }
return x * f;
}
const int N = 1007;
int t,cnt,ans;
struct Point {
int x,y;
}p[N],a,b,st;
inline int dist(Point p1,Point p2) {
return abs(p1.x-p2.x) + abs(p1.y-p2.y);
}
signed main()
{
p[0].x = read(), p[0].y = read(), a.x = read(), a.y = read(), b.x = read(), b.y = read();
st.x = read(), st.y = read(), t = read();
int X,Y;
for(X=a.x*p[0].x+b.x, Y=a.y*p[0].y+b.y; X<=INF && Y<=INF && X>=0 && Y>=0; X=a.x*X+b.x,Y=a.y*Y+b.y) {
p[++cnt].x = X, p[cnt].y = Y;
//printf(" <%lld,%lld>\n",X,Y);
}
//printf("Why %d %d\n",X,Y);
//for(int i=0;i<=cnt;++i) printf("(%lld,%lld)\n",p[i].x,p[i].y);
//printf(" INF = %lld\n",INF);
//printf("%lld\n",cnt);
for(int i=0;i<=cnt;++i) {
int tmp = t, res = 1;
tmp -= dist(st,p[i]);
if(tmp < 0) continue;
while(tmp-dist(p[i],p[i+res]) >= 0 && i+res<=cnt) ++res;
ans = max(ans,res);
res = 1;
while(i-res>=0 && tmp-dist(p[i],p[i-res]) >= 0) ++res;
ans = max(ans,res);
}
printf("%lld\n",ans);
return 0;
}
/*
1 1 2 2 0 0
51531 51321 5153151
*/
E
Digging, to be completed
F
Digging, to be completed