A. Abyss water demon
Meaning: find all extremely long non strict rising segments, find out those segments with the largest right endpoint weight - left endpoint weight, and output endpoint coordinates.
I can't stand it. I didn't see the problem wa during the game
Idea: the top rising subsequence model, double pointers, find the maximum weight of the two points in the interval, and then traverse it to output the left and right endpoint values of the interval that meet the requirements.
code:
#include<bits/stdc++.h> using namespace std; const int N=1e5+10; int n,a[N]; void solve() { cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; int maxn=0; for(int i=1;i<=n;i++){ int j=i; while(j+1<=n&&a[j+1]>=a[j]) j++; maxn=max(maxn,a[j]-a[i]); i=j; } for(int i=1;i<=n;i++){ int j=i; while(j+1<=n&&a[j+1]>=a[j]) j++; if(a[j]-a[i]==maxn) cout<<i<<' '<<j<<' '; i=j; } cout<<endl; } int main() { int _; cin>>_; while(_--){ solve(); } return 0; }
B. Naughty devil
Meaning:
Your manor is a piece of n × m's lawn.
Now some grids are ordinary plants P, some grids are radish umbrellas * and some grids are zombies Z. (zombies already on the grid will not eat plants or move)
tip: radish umbrella can protect the surrounding 3 × 3, that is, a radish umbrella located at position (x,y)(x,y)(x,y) can protect plants located on (x ± 1,y),(x,y ± 1),(x ± 1,y ± 1) and their nine grids.
Now you want to know, for such a given lawn, suppose there are infinite snitches, what is the maximum number of plants that can be stolen.
Idea: enumerate each point and find the plants that are not protected by the radish umbrella. ps: memset(g,0,sizeof(g)) cannot be used to empty the array every time, which will lead to TLE, because this T has been repeated several times and is difficult to top.
code:
#include<bits/stdc++.h> #define IOS std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define INF 0x3f3f3f3f using namespace std; typedef long long LL; typedef pair<int,int> PII; typedef pair<double,double> PDD; const int N=1e3+10; int n,m; int t; int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0}; int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1}; int main() { cin>>t; while(t--) { char g[N][N]; int ans=0; cin>>n>>m; for(int i=0;i<=n+1;i++) for(int j=0;j<=m+1;j++) g[i][j]='Z'; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { cin>>g[i][j]; if(g[i][j]=='P') ans++; } for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { if(g[i][j]=='*') { for(int k=0;k<8;k++) { int x=i+dx[k],y=j+dy[k]; if(g[x][y]=='P'){ ans--; g[x][y]='Z'; } } } } } cout<<ans<<endl; } return 0; }
C. Dead Sandworm
Meaning:
At the beginning, you have NNN yuan RMB in your hand.
The trading rules are as follows:
Given n and m, please answer how much consumption experience you finally gained.
Idea: you can simulate according to the given rules. You need to pay attention to the problem of accuracy. When you carelessly see a decimal during the competition, you don't consider the accuracy. QwQ
code:
#include<bits/stdc++.h> #define IOS std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define INF 0x3f3f3f3f using namespace std; typedef long long LL; typedef pair<int,int> PII; typedef pair<double,double> PDD; const int N=1e3+10; int n; double m; int t; int dx[8]={1,0,-1,0,1,1,-1,-1},dy[8]={0,1,0,-1,1,-1,1,-1}; int main() { cin>>t; while(t--) { LL ans=0; cin>>n>>m; LL red=0,green=0,temp; temp=100*m-100; LL now=n; while(now) { red+=now*100; green+=min(10000LL,temp*now); now=0; now+=red/200; ans+=red/10; ans+=green/10; red=0; green=0; } cout<<ans<<endl; } return 0; }
D. Jungle Trojan horse
Meaning:
As we all know, if you are given two numbers a and B, you need to calculate a × B = the value of C, you know what to do: multiply each bit and multiply them by 10^k, and then add them, where k represents the power of the corresponding digit.
Once, poor ZM accidentally turned all multiplication operations in "multiplication" into addition. She wanted you to help with the calculation. What was the result?
Idea: it's not difficult to see the example. The result is that the length of each value b of a plus each value a of b is actually the length of ab + the length of ba.
code:
//Is to write me a complex QAQ #include<bits/stdc++.h> using namespace std; const int MOD=998244353; typedef long long LL; LL quick_power(LL a,LL b,LL p) { LL ans=1; while(b) { if(b&1) ans=(ans%p*a%p)%p; b>>=1; a=(a%p*a%p)%p; } return ans%p; } int main() { int t; cin>>t; while(t--) { string a,b; cin>>a>>b; LL ans=0; LL la=a.size(),lb=b.size(); for(LL i=0;i<la;i++) ans=(ans%MOD+quick_power(10, la-i-1, MOD)*(a[i]-'0')%MOD*lb%MOD)%MOD; for(LL i=0;i<lb;i++) ans=(ans%MOD+quick_power(10, lb-i-1, MOD)*(b[i]-'0')%MOD*la%MOD)%MOD; cout<<ans%MOD<<endl; } }
#python version t=int(input()) for i in range(t): a,b=input().split() m=min(len(a),len(b)) print((int(a)*len(b)+int(b)*len(a))%998244353)