#include "stdafx.h" #define N 8 #include using namespace std; class number{ int up; int down; public: number(const number& n):up(n.up),down(n.down){} number(int n=0):up(n),down(1){} number& operator+=(const number& n); number& operator-=(const number& n); number& operator*=(const number& n); number& operator/=(const number& n); bool is_zero()const{return down!=0&&up==0;} bool is_valid()const{return down!=0;} bool is_one()const{return down!=0&&up==down;} bool operator==(const number& n)const{return is_valid()&&n.is_valid()&&n.down*(long long)up==n.up*(long long)down;} bool operator<(const number& n)const; bool operator>(const number& n)const{return n<*this;} bool operator<=(const number& n)const{return !(*this>n);} bool operator!=(const number& n)const{return !(n==*this);} bool operator>=(const number& n)const{return !(*this=0?up:-up;x.down=down>=0?down:-down;return x;} }; number& number::operator +=(const number& n) { up=up*n.down+down*n.up; down*=n.down; return *this; } number& number::operator -=(const number& n) { up=up*n.down-down*n.up; if(up<0)up=-up; down*=n.down; return *this; } number& number::operator *=(const number& n) { up*=n.up; down*=n.down; return *this; } number& number::operator /=(const number& n) { down*=n.up; up*=n.down; return *this; } bool number::operator <(const number &n)const { return (long long)up*n.down=yu){ if(yu==BUFF_LEN){ yu=fread(buff,sizeof(number),BUFF_LEN,pFile); start=0; if(yu==0)break; }else break; } } printf("r[%d]=%d\n",i,x); fclose(pFile); } void save_set(const set& result, int x[],int size) { int mask=0; int i; char fName[20]; for(i=0;i::const_iterator cit; i=j=0; for(cit=result.begin();cit!=result.end();++cit){ buff[j++]=*cit; i++; if(j==BUFF_LEN){ j=0; fwrite(buff,sizeof(number),BUFF_LEN,pFile); } } if(j>0){ fwrite(buff,sizeof(number),j,pFile); } fclose(pFile); if((mask&(mask+1))==0){ output_r(size); } } void add_result(set& result, int y[],int yc,int z[],int zc) { int mask=0; int i,j; char fName[20]; FILE *yFile,*zFile; int yu,zu; if(yc<=2){ if(yc==1){ yu=1; buff[0]=y[0]; }else{ yu=5; buff[0]=y[0]+y[1]; buff[1]=abs(y[0]-y[1]); buff[2]=y[0]*y[1]; buff[3]=number(y[0])/y[1]; buff[4]=number(y[1])/y[0]; } yFile=NULL; }else{ mask=0; for(i=0;i result; for(i=1;i<(1<0){ if(x&1)c++; x>>=1; } return c; } int _tmain(int argc, _TCHAR* argv[]) { system("mkdir data"); int x[]={1,2,3,4,5,6,7,8}; int i; for(i=7;i<1<<12;i++){ if(bc(i)<=8){ int j=0,k; for(k=0;k<12;k++){ if(i&(1<