To the unconscious self
Question B: fast power + Fast Multiplication
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll qu(ll a,ll b,ll p) { ll ans=0; a%=p; while(b) { if(b%2) ans=(ans+a)%p; b>>=1; a=(a+a)%p; } return ans%p; } ll qui(ll a,ll b,ll p) { ll ans=1; a%=p; while(b) { if(b%2==1) ans=qu(ans,a,p); b>>=1; a=qu(a,a,p); } return ans; } int main() { ll n,a,b,p; cin>>n; while(n--) { cin>>a>>b>>p; cout<<qui(a,b,p)<<endl; } return 0; }
Question E: two points (I have seen the questions, but I haven't finished them well)
#include<iostream> #include<algorithm> using namespace std; typedef long long ll; const ll maxn=100005; ll L[maxn*2]; ll ans,n,k,sum; void solve(ll l,ll r) { if(l>=r) return ; ll t=(l+r)/2+1; sum=0; for(ll i=0;i<n;++i) { sum=sum+L[i]/t; } if(sum>=k) { ans=max(t,ans); solve(t,r); } else solve(l,t-1); } int main() { ll i; cin>>n>>k; ll t=0; for(i=0;i<n;i++) cin>>L[i],t+=L[i]; t/=k; // cout<<t<<endl; solve(0,t); cout<<ans<<endl; return 0; }
Question J: Find function (not long ago, I used this find function. I didn't think about the amount of data carefully, but I thought of ac automata. ac automata is totally wrong. If any big guy wrote out a problem, please give me the address and give me a new look!!!)
#include<bits/stdc++.h> using namespace std; const int maxn=1000005; string a,b; int main() { int n,i,j; cin>>a; cin>>n; while(n--) { cin>>b; string::iterator it1=b.begin(),it2=a.begin(); bool f=1; while(it1<b.end()&&it2<a.end()) { it2=find(it2,a.end(),*it1); it1++; it2++; } if(it1==b.end()&&it2<=a.end()) cout<<"Yes"; else cout<<"No"; cout<<"\n"; } return 0; }
Above.