A. ConneR and the A.R.C. Markland-N (CF 1293 A)
Subject to the effect
\ (n-\) floors, each have a restaurant, but \ (K \) restaurants not open, respectively \ (a_i \) layer, \ (Colin \ "Conner" \ Neumann \ Jr's \) in the first \ (s \) layer, and now he wants to go to lunch and asked him to go to the smallest cross-floor restaurant is how much?
Problem-solving ideas
\ (n-\) great but \ (K \) is small, with \ (SET \) stored \ (a_i \) , take the two pointers from the \ (S \) up to down scan restaurant is not closed, i.e., can.
Magic code
#include <bits/stdc++.h>
#define MIN(a,b) ((((a)<(b)?(a):(b))))
#define MAX(a,b) ((((a)>(b)?(a):(b))))
#define ABS(a) ((((a)>0?(a):-(a))))
using namespace std;
int main(void) {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int kase; cin>>kase;
for (int i = 1; i <= kase; i++) {
int n,s,k;
cin>>n>>s>>k;
set<int> qwq;
for(int u,i=1;i<=k;++i){
cin>>u;
qwq.insert(u);
}
int l=s;
int r=s;
while(true){
if (l>=1) if (qwq.find(l)!=qwq.end()) --l; else break;
if (r<=n) if (qwq.find(r)!=qwq.end()) ++r; else break;
}
int ans=0;
if (l==0) ans=r-s;
else if (r==n+1) ans=s-l;
else ans=min(s-l,r-s);
cout<<ans<<endl;
}
return 0;
}
B. JOE is on TV! (CF 1293 B)
Subject to the effect
The initial \ (n \) opponents, answer questions, wrong answers out, a round, there \ (s \) opponent, the bout if there \ (t \) opponents got it wrong, then you can get \ (\ dfrac {t} {s} of $ \) . The maximum number of dollars you may be asked to get how much?
Problem-solving ideas
After several enumeration we can guess each time a person got it wrong, the largest number of dollar finally obtained, the following as proof:
There are currently provided \ (T \) players, if there are current return \ (s (s> 1) \) players wrong answers, the dollar is obtained as \ (\ S dfrac {} {} T \) , since \ (\ dfrac {. 1} {Ti}> \ dfrac {. 1} {T} (I \ GEQ. 1) \) , so \ (\ sum \ limits_ {i = 0} ^ {s-1} \ dfrac {1} Ti} {> \ SUM \ limits_ I = {0} ^ {S-1} \ dfrac {1} {} T = \ dfrac {S} {} T \) , so every \ (1 \) players A when the dollar finally obtained the wrong number is the largest.
Magic code
#include <bits/stdc++.h>
#define MIN(a,b) ((((a)<(b)?(a):(b))))
#define MAX(a,b) ((((a)>(b)?(a):(b))))
#define ABS(a) ((((a)>0?(a):-(a))))
using namespace std;
template <typename T>
void read(T &x) {
int s = 0, c = getchar();
x = 0;
while (isspace(c)) c = getchar();
if (c == 45) s = 1, c = getchar();
while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
if (s) x = -x;
}
template <typename T>
void write(T x, char c = ' ') {
int b[40], l = 0;
if (x < 0) putchar(45), x = -x;
while (x > 0) b[l++] = x % 10, x /= 10;
if (!l) putchar(48);
while (l) putchar(b[--l] | 48);
putchar(c);
}
int main(void) {
int n;
read(n);
double ans=0;
for(int i=1;i<=n;++i) ans+=1.0/(double)(n-i+1);
printf("%.6f\n",ans);
return 0;
}
C. NEKO's Maze Game (CF 1293 C)
Subject to the effect
Given a \ (2 * n \) rectangular grid, you want \ ((1,1) \) went \ ((2, the n-) \) , there \ (q \) in time, the \ ( I \) time, \ ((r_i, C_i) \) state of the grid will be inverted, i.e., to go away from the non-variant, or variant can not go away. The initial grid can all go, ask each moment later, you can from \ ((1,1) \) went \ ((2, the n-) \) .
Problem-solving ideas
Notice can not achieve the distribution grid can not go only two, the first two columns of a grid are not gone, and the second is adjacent columns of different rows of the grid can not go, the two were statistically distribution number, greater than \ (0 \) is not reachable, otherwise reach.
Magic code
#include <bits/stdc++.h>
#define MIN(a,b) ((((a)<(b)?(a):(b))))
#define MAX(a,b) ((((a)>(b)?(a):(b))))
#define ABS(a) ((((a)>0?(a):-(a))))
using namespace std;
template <typename T>
void read(T &x) {
int s = 0, c = getchar();
x = 0;
while (isspace(c)) c = getchar();
if (c == 45) s = 1, c = getchar();
while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
if (s) x = -x;
}
template <typename T>
void write(T x, char c = ' ') {
int b[40], l = 0;
if (x < 0) putchar(45), x = -x;
while (x > 0) b[l++] = x % 10, x /= 10;
if (!l) putchar(48);
while (l) putchar(b[--l] | 48);
putchar(c);
}
const int N=1e5+8;
int val[2][N],cnt,n,q;
int main(void) {
read(n);
read(q);
val[0][0]=val[1][0]=val[0][n+1]=val[1][n+1]=-1;
for(int r,c,i=1;i<=q;++i){
read(r);
read(c);
r--;
val[r][c]^=1;
if (val[r][c]==1&&val[r^1][c]==1) ++cnt;
if (val[r][c]==0&&val[r^1][c]==1) --cnt;
if (val[r][c]==1&&val[r^1][c-1]==1) ++cnt;
if (val[r][c]==0&&val[r^1][c-1]==1) --cnt;
if (val[r][c]==1&&val[r^1][c+1]==1) ++cnt;
if (val[r][c]==0&&val[r^1][c+1]==1) --cnt;
if (cnt) puts("No"); else puts("Yes");
}
return 0;
}
D. Aroma's Search (CF 1293 D)
Subject to the effect
Given a coordinate, there are a lot of data packets, an initial data packet position \ ((x_0, y_0) \ ) , the data packets by the following recursive formula \ (x_n = a_x \ times x_ {n-1} + b_x, y_n = a_y \ times y_ {n -1} + b_y \) is given, the \ (I \) th data packet number is \ (I \) , coordinates \ ((x_i, y_i) \) . \ (Aroma \ White \) initial position is \ ((X_s, Y_S) \) , it can move up and down \ (t \) times, and asked him to collect up to how many packets.
Problem-solving ideas
Notice \ (a_x, a_y, b_x, b_y \) greater than \ (0 \) , the coordinates of those packets will become increasingly large, the distance between them will be growing, so when the \ (Aroma \ White \ ) when a packet arrives, it is clear that we are to label small packets to run is the best. The first \ (I \) data packet and the \ (i-1 \) Manhattan distance data packet is \ ((a_x-1) * x_ {i-1} + b_x + (a_y-1) * y_ {i + b_y} -1 \) , i.e., the extreme case is \ (a_x = a_y = 2, b_x = b_y = 0 \) when this time is from \ (x_ {i-1} + y_ {i-1} \) , since \ (T \ Leq 10 ^ {16} \) , so that the coordinate data packets we enumerate \ (10 ^ {16} \) can, since the coordinates are in the recursive exponential growth enumeration data packet at most \ (\ log_2 {10 ^ { 16}} \ approx 53 \) a, properly due \ (O ({53} ^ 2) \) violent enumerated first to arrive greedy packet number can take the maximum number of seek. Note that if the first to reach the first \ (k \) packets, and finally to the first \ (0 \) packets can continue to move, then, will continue to enumerate the first \ (k + 1 \) packets and more to see can arrival.
Magic code
#include <bits/stdc++.h>
#define MIN(a,b) ((((a)<(b)?(a):(b))))
#define MAX(a,b) ((((a)>(b)?(a):(b))))
#define ABS(a) ((((a)>0?(a):-(a))))
using namespace std;
const LL N=10000000000000000ll+8;
vector<pair<LL,LL>> pos;
int check(int x,LL xs,LL ys,LL t){
int cnt=0;
for(int i=x;i>=0;--i){
LL dis=abs(pos[i].first-xs)+abs(pos[i].second-ys);
if (dis<=t){
t-=dis;
xs=pos[i].first;
ys=pos[i].second;
++cnt;
}
else return cnt;
}
int len=pos.size();
for(int i=x+1;i<len;++i){
LL dis=abs(pos[i].first-xs)+abs(pos[i].second-ys);
if (dis<=t){
t-=dis;
xs=pos[i].first;
ys=pos[i].second;
++cnt;
}
else return cnt;
}
return cnt;
}
int main(void) {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
LL x0,y0,ax,ay,bx,by;
cin>>x0>>y0>>ax>>ay>>bx>>by;
LL xs,ys,t;
cin>>xs>>ys>>t;
pos.push_back(make_pair(x0,y0));
while(x0<N||y0<N){
if (x0>=ax*x0+bx) break;
x0=ax*x0+bx;
if (y0>=ay*y0+by) break;
y0=ay*y0+by;
pos.push_back(make_pair(x0,y0));
}
int ans=0;
int len=pos.size();
for(int i=0;i<len;++i)
ans=max(ans,check(i,xs,ys,t));
printf("%d\n",ans);
return 0;
}
The first cross-MLE cynicism? ? I have 53 points how MLE? ? Later, we found a long long overflow and enumerated data packet not stop