A:百钱买百鸡
#include <bits/stdc++.h>
using namespace std;
int main()
{
int x,y,z,i,j,n,x1[100],y1[100],z1[100],c,q;
while(scanf("%d",&n)!=EOF)
{
c=0;
for(x=0;x<=n;x++)
{
for(y=0;y<=n;y++)
{
z=n-x-y;
........
}
if(c==0)
printf("No Answer\n");
else
{
for(i=1;i<=c;i++)
{
j=101;
if(x1[i]<j)
{
j=x1[i];
q=i;
}
else if(x1[i]=j)
{
if(y1[i]<y1[i-1])
q=i;
else if(z1[i]<z1[i-1])
q=i;
}
printf("%d %d %d\n",x1[q],y1[q],z1[q]);
}
}
}
return 0;
}
B:火柴棒等式
#include <bits/stdc++.h>
using namespace std;
int a[2223]= {6,2,5,5,4,5,6,3,7,6};
const int b[10]= {6,2,5,5,4,5,6,3,7,6};
int need(int n)
{
int t, num;
num=0;
if(n==0) return 6;
while(n>0)
{
t=n%10;
num+=b[t];
n/=10;
}
return num;
}
int main( )
{
int n,i,j,A,B,C,D,sum;
scanf("%d",&n);
sum=0;
for(i=10; i<2223; i++)
a[i]=need(i);
for(i=0; i<=1000; i++)
{
for(j=0; j<=1000; j++)
{
......
......
if(D==C) sum++;
}
}
printf("%d\n",sum);
return 0;
}
C:二分查找
#include <bits/stdc++.h>
using namespace std;
int a[1000005],n,t;
int BS(){
int l=0,r=n-1;
while(l<=r){
int m=(l+r)>>1;
if(t<a[m])
r=m-1;
else if(t>a[m])
l=m+1;
else if(a[m-1]<t)
return m;
else r=m-1;
}
return -1;
}
int main(){
while(~scanf("%d",&n)){
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
scanf("%d",&t);
......
.....
else{
int f=BS();
if(f!=-1){
printf("%d\n",f+1);
}
else
puts("None");
}}
return 0;
}
D:解方程
#include <bits/stdc++.h>
using namespace std;
int n,x;
int a[1000];
int bsearch(int left,int right,int x)
{
if(left>right)
return -1;
int mid=(left+right)/2;
if(a[mid]==x)
{
if(mid>0&&a[mid-1]==x)
return bsearch(left,mid-1,x);
else
return mid;
}
else if(a[mid]<x)
return bsearch(mid+1,right,x);
else
return bsearch(left,mid-1,x);
}
int gao()
{
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(........)
return 1;
}
}
return 0;
}
int main()
{
while(cin>>n>>x)
{
for(int i=0;i<n;i++)
cin>>a[i];
sort(a,a+n);
gao()
if(gao())//IIIKTU
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
}
正整数解(2)
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
while(cin>>n)
{
int flag=0;
for(int x=1;x<n-1;x++)
.......
cout<<flag<<endl;
}
return 0;
}