思路:本题目多通过高斯消元和线性无关等进行,需要进行适当的数论分析。难度在于数学。具体可以参看点击打开链接
源码:
#include
using namespace std;
const int maxn=1000;
int mp[1000][1000];
int main()
{
int W,H,cnt=0;
cin>>W>>H;
for(int i=0;i=0) mp[i-2][j]=1;
if(j+2=0) mp[i][j-2]=1;
}
}
cout<
源码:
#include
using namespace std;
const int maxn = 1000+1;
const int INF = 0x3f3f3f3f;
int main()
{
int n,x[maxn],y[maxn],ans=INF;
cin>>n;
for(int i=0;i>x[i];
for(int i=0;i>y[i];
for(int i=0;i
源码:
#include
using namespace std;
const int maxn = 210;
bool judge(char c[],int clength)
{
for(int i=0;i>A>>B;
for(int i=0;i<=A.length();i++)
{
int k=0;
for(int j=0;j
源码:
#include
using namespace std;
const long long M =1000000007;
struct state
{
long long st;
int step;
};
int main()
{
long long x;
int ans;
bool flag=false;
queue q;
map mp;
cin>>x;
state xst={x,0};
q.push(xst);
mp[x%M]=1;
while(!q.empty())
{
state nst=q.front();
q.pop();
if(nst.st%M==0)
{
flag = true;
ans=nst.step;
break;
}
if(nst.step>100000) break;
long long newx;
newx = (4*nst.st+3)%M;
if(!mp.count(newx))
{
state newst={newx,nst.step+1};
q.push(newst);
mp[newx]=1;
}
newx = (8*nst.st+7)%M;
if(!mp.count(newx))
{
state newst={newx,nst.step+1};
q.push(newst);
mp[newx]=1;
}
}
if(flag) cout<
源码:
#include
using namespace std;
const int maxn = 110;
int cmp(string a,string b)
{
return a.compare(b)<0;
}
int main()
{
int n;
bool flagd=true,flagl=true;
cin>>n;
string s[maxn],spy[maxn];
for(int i=0;i>s[i];
spy[i]=s[i];
}
sort(spy,spy+n,cmp);
for(int i=0;i=s[i+1].length())
{
flagl=false;
break;
}
}
if(flagd&&flagl) cout<<"both"<
源码:
#include
using namespace std;
bool judge1(string s)
{
for (int i=0;i>s;
if(judge1(s)&&judge2(s)&&judge3(s)) cout<<"Likes"<
源码:
#include
using namespace std;
int main()
{
int N,f[2],ans;
cin>>N;
f[0]=0;
f[1]=1;
while(!(f[1]>N||f[0]>N))
{
f[0]=f[0]+f[1];
if(f[0]>N) break;
f[1]=f[0]+f[1];
}
ans=min(abs(f[0]-N),abs(f[1]-N));
cout<
思路:本题如果采取枚举,会超时。只能通过80%的数据。本题的解法非常巧妙,具体可以参看牛客网解法中第一个的解法
源码:枚举(80%通过)
#include
using namespace std;
const int maxn = 25;
int main()
{
//freopen("datain.txt","r",stdin);
int n,a[maxn],ans,minv,maxv=0;
bool flag=false;
cin>>n;
for(int i=0;i>a[i];
maxv+=a[i];
}
sort(a,a+n);
minv=a[0];
ans = maxv+1;
for(int i=minv;i<=maxv;i++)
{
flag=false;
int pend,sum=0;
for(int j=0;j=i)
{
pend = j;
break;
}
}
int len = pend+1;
for(int m=0;m<(1<<(len));m++)
{
int sum = 0;
for(int k=0;k