A-complete k-fork tree
meaning of the title
It is known that a complete (k) fork tree has (n) nodes. The distance between the two farthest points on the tree is calculated, and the distance between the nodes is 1.
Basic Ideas
If the depth of the tree is (h), then the distance between the two points of the full (k) fork tree is ((h-1)*2), and the number of nodes in the remaining layer is judged as \(rest\). If \\\\\\\\\\\
#include<bits/stdc++.h> #define FOR(i,a,b) for(int i=a;i<b;i++) #define FOR2(i,a,b) for(int i=a;i<=b;i++) #define sync ios::sync_with_stdio(false);cin.tie(0) #define ll long long #define MAXN 100010 using namespace std; int main() { ll count=0,t,n,k;cin>>t; while(t--) { count=0;ll h=0; cin>>k>>n; if(k==1){ cout<<n-1<<endl;continue; } ll sum=0,tmp=1; while(1) { sum+=tmp; tmp*=k; h++; if(tmp+sum>=n)break; } ll ans=(h-1)*2; n=n-sum; if(n>tmp/k) { ans+=2; } else if(n>=1) { ans++; } cout<<ans<<endl; } return 0; }
B Distance Generates Beauty
meaning of the title
A series of numbers to find the smallest modifier of the difference (>= k)between all adjacent numbers
Basic Ideas
Differential scanning, and then scanning, if swept to a certain interval (<k) then note (cnt++,i++)
Notice the absolute value
#include<bits/stdc++.h> #define FOR(i,a,b) for(int i=a;i<b;i++) #define FOR2(i,a,b) for(int i=a;i<=b;i++) #define sync ios::sync_with_stdio(false);cin.tie(0) #define ll long long #define MAXN 100010 using namespace std; int arr[MAXN],brr[MAXN]; int main() { ll n,k,cnt=0;cin>>n>>k; FOR(i,0,n){ cin>>arr[i]; if(i!=0)brr[i]=arr[i]-arr[i-1]; } FOR(i,1,n) { if(abs(brr[i])<k) { cnt++; i++; } } cout<<cnt<<endl; return 0; }
C toast
Fundamental Implications
Seek the results of (n!!!!!!) pairs of (k) modules
Basic Ideas
If a multiplication is made, the result will be zero, so the cycle will not exceed (k)
#define FOR(i,a,b) for(int i=a;i<b;i++) #define FOR2(i,a,b) for(int i=a;i<=b;i++) #define sync ios::sync_with_stdio(false);cin.tie(0) #define ll long long #define MAXN 100010 using namespace std; int main() { ll n,mod,ans=1; cin>>n>>mod; if(n>=mod) { cout<<0<<endl;return 0; } FOR(i,1,n+1) { ans=(ans*i); if(ans>=mod) { cout<<0<<endl;return 0; } } n=ans;ans=1; FOR(i,1,n+1) { ans=(ans*i); if(ans>=mod) { cout<<0<<endl;return 0; } } n=ans;ans=1; FOR(i,1,n+1) { ans=(ans*i)%mod; } cout<<ans<<endl; return 0; }
F triple
meaning of the title
Given (n) triples \((a_i,b_i,c_i)) a pair of ([i, j] (i <= j)\), satisfying \(2*min (a_i+a_j, b_i+b_j)\\\\\\\\\\\\\
Basic Ideas
Each triple adds an attribute (2*a_i-b_i\) to rank the attributes, finds the prefix and sum of (c_i), and then manually divides (max(posr) so that (2*a_1+2*a_{posr}-b_1-b_{posr}= 0)\
Choose the starting point for ([1,posr]) and scan backward and forward to determine the end point, because if ([i,j]), there must be ([i+1, k] (k <= j)\); find it and use \(c_i*sum[i,j] to find out the increase. Sort twice.
#include<bits/stdc++.h> #define FOR(i,a,b) for(int i=a;i<b;i++) #define FOR2(i,a,b) for(int i=a;i<=b;i++) #define sync ios::sync_with_stdio(false);cin.tie(0) #define ll long long #define MAXN 100010 #define MOD (1000000000+7) #define debug cout<<"debug"<<endl using namespace std; typedef struct{ ll a,b,c,trans; }NODE;NODE nodes[MAXN]; ll n,sum[MAXN]; bool cmp(NODE n1,NODE n2) { return n1.trans<n2.trans; } ll solve() { sort(nodes+1,nodes+n+1,cmp); sum[1]=nodes[1].c; FOR2(i,2,n) { sum[i]=nodes[i].c+sum[i-1]; } ll l=1,r=n,posr=0; while(l<=r) { ll mid=(l+r)/2; if(nodes[mid].trans+nodes[1].trans>0){ r=mid-1; } else { posr=mid;l=mid+1; } } ll res=0; for(l=1,r=posr;l<=r;l++) {//Determine the starting point while(l<=r&&nodes[l].trans+nodes[r].trans>0) { r--; posr--; } if(r<l) break; res=(res+((sum[r]-sum[l-1])%MOD)*nodes[l].c)%MOD; //The sum of L~R } return res; } int main() { cin>>n; FOR2(i,1,n) { cin>>nodes[i].a>>nodes[i].b>>nodes[i].c; nodes[i].trans=2*nodes[i].a-nodes[i].b; } ll ans=solve(); FOR2(i,1,n) { nodes[i].trans=2*nodes[i].b-nodes[i].a; } ans+=solve(); cout<<ans%MOD<<endl; return 0; }
G Basketball School Match
meaning of the title
n individuals, each person has 5 attributes. The maximum attributes of 5 persons can be selected and only one person can be selected for each attribute.
Basic Ideas
Use interpolation to select the top five people for each attribute, and then search for them by dfs
#include<bits/stdc++.h> #define FOR(i,a,b) for(int i=a;i<b;i++) #define FOR2(i,a,b) for(int i=a;i<=b;i++) #define sync ios::sync_with_stdio(false);cin.tie(0) #define ll long long #define MAXN 100010 using namespace std; typedef struct{ int state[6]; }NODE;NODE nodes[MAXN]; int maxp[6][6]; int vis[MAXN]; ll ans=0;int n; void dfs(ll level,ll res) { if(level==6) { ans=max(ans,res); return; } else { for(int i=1;i<=5;i++) { if(vis[maxp[i][level]]==1)continue; vis[maxp[i][level]]=1;//Record selected players dfs(level+1,res+nodes[maxp[i][level]].state[level]); vis[maxp[i][level]]=0; } } } int main() { cin>>n; FOR2(i,1,n) { for(int j=1;j<=5;j++) { cin>>nodes[i].state[j]; for(int k=1;k<=5;k++) {//Comparing one by one with five elements if(nodes[i].state[j]>nodes[maxp[k][j]].state[j]) {//Insertion sort for(int h=5;h>=k+1;h--) maxp[h][j]=maxp[h-1][j]; maxp[k][j]=i; break; } } } } for(int i=1;i<=5;i++) { vis[maxp[i][1]]=1; dfs(2,nodes[maxp[i][1]].state[1]); vis[maxp[i][1]]=0; } cout<<ans<<endl; return 0; }
H Distribution of Student Numbers
meaning of the title
Give a bunch of numbers, and find the sum of the minimum numbers that make them different from each other. Each number can only be increased and can not be reduced.
Basic Ideas
Sort, and then find out the number each person can choose, that is, the minimum number that can rise (if less than the previous, then at least rise to the previous + 1), (max(a[i-1]+1,a[i])-a[i]+1), pay attention to invariance is also an option, and then multiply.
#include<bits/stdc++.h> #define FOR(i,a,b) for(int i=a;i<b;i++) #define FOR2(i,a,b) for(int i=a;i<=b;i++) #define sync ios::sync_with_stdio(false);cin.tie(0) #define ll long long #define MAXN 100010 #define MOD (1000000000+7) using namespace std; ll n,arr[MAXN],brr[MAXN]; int main() { cin>>n; FOR2(i,1,n) { cin>>arr[i]; } sort(arr+1,arr+1+n); ll ans=1; FOR2(i,1,n) { if(i!=1) { brr[i]=max(arr[i-1]+1,arr[i])+1-arr[i]; arr[i]=max(arr[i-1]+1,arr[i]); ans=(ans*brr[i])%MOD; } } cout<<ans%MOD<<endl; return 0; }
I Gree's atrium
meaning of the title
Give n*m matrix and k boxes, the boxes are placed randomly, and find the shortest path length from left to right, if it can not reach output-1;
Basic Ideas
The maximum k is not more than (n-1)(m-1), and the path is n+m-2.
#include<bits/stdc++.h> #define FOR(i,a,b) for(int i=a;i<b;i++) #define FOR2(i,a,b) for(int i=a;i<=b;i++) #define sync ios::sync_with_stdio(false);cin.tie(0) #define ll long long #define MAXN 100010 using namespace std; int main() { ll n,m,k;cin>>n>>m>>k; if(k>(n-1)*(m-1)) { cout<<-1<<endl; } else{ cout<<n+m-2<<endl; } return 0; }