版权声明:随意转载 https://blog.csdn.net/nuiniu/article/details/88555458
给不开窍的自己
B题:快速幂 + 快速乘(脑子不够灵光,知道快速幂,却不会联想到快速乘)
#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;
}
E题:二分(见过的题目,却没有好好去做完)
#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;
}
J题:find函数(不久前还用了这个find函数,没仔细考虑数据量,却想到了ac自动机,ac自动机是完全错的,如果有大佬写出来了麻烦给下地址,给萌新瞅瞅!!!)
#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;
}
以上。