Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

1A过了,附代媽,给幾组数据

Posted by KatrineYang at 2016-09-24 09:29:36 on Problem 1348 and last updated at 2016-09-24 09:30:55
1.除法注意精度
2.乘和除注意零的问题
3.中间结果可能大于100,可能是负数,也可能不是整数
4.注意输出OK!而不是YES!
5.嫑忘了两两组合的情况
数据:
2 0 0 5 9
NO!
2 2 13 13 24
OK!
7 19 25 4 233
OK!
5 53 32 53 233
OK!

代媽:
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <iomanip>
using namespace std;

double shu[4], tar;

int pl[24][4] = {{0,1,2,3},{0,1,3,2},{0,2,1,3},{0,2,3,1},{0,3,1,2},{0,3,2,1},
				{1,0,2,3},{1,0,3,2},{1,2,0,3},{1,2,3,0},{1,3,0,2},{1,3,2,0},
				{2,1,0,3},{2,1,3,0},{2,0,1,3},{2,0,3,1},{2,3,0,1},{2,3,1,0},
				{3,0,1,2},{3,0,2,1},{3,1,0,2},{3,1,2,0},{3,2,0,1},{3,2,1,0}};

bool ok(double *sz, int gs, double tar){
	switch(gs){
		case 2:{
			//cout << sz[0] << " " << sz[1] << " " << tar << endl;
			return abs(sz[0]+sz[1]-tar)<1e-6 || abs(sz[0]-sz[1]-tar)<1e-6 || abs(sz[0]*sz[1]-tar)<1e-6 || (sz[1]!=0 && abs(sz[0]*1.0/sz[1]-tar)<1e-6);
		}
		case 3:{
			//cout << sz[0] << " " << sz[1] << " " << sz[2] << " " << tar << endl;
			return (sz[0]==0 && tar==0) ||
					ok(sz+1,2,tar-sz[0]) ||
					ok(sz+1,2,sz[0]-tar) ||
					(sz[0]!=0 && ok(sz+1,2,tar/sz[0])) ||
					(tar!=0 && sz[0]!=0 && ok(sz+1,2,sz[0]/tar)) ||
					(sz[2]==0 && tar==0) ||
					ok(sz,2,tar-sz[2]) ||
					ok(sz,2,tar+sz[2]) ||
					(sz[2]!=0 && ok(sz,2,tar/sz[2])) ||
					(sz[2]!=0 && ok(sz,2,tar*sz[2]));
		}
		case 4:{
			if((sz[0]*sz[1]*sz[2]*sz[3]==0) && tar==0) return 1;
			double szz[4];
			for(int i = 0; i < 24; i++){
				for(int j = 0; j < 4; j++) szz[j] = sz[pl[i][j]];
				double qlg[4], hlg[4];
				qlg[0]=szz[0]+szz[1], qlg[1]=szz[0]-szz[1], qlg[2]=szz[0]*szz[1];
				qlg[3] = (szz[1]!=0) ? (szz[0]*1.0/szz[1]) : qlg[0];
				hlg[0]=szz[2]+szz[3], hlg[1]=szz[2]-szz[3], hlg[2]=szz[2]*szz[3];
				hlg[3] = (szz[3]!=0) ? (szz[2]*1.0/szz[3]) : hlg[0];
				for(int j = 0; j < 4; j++){
					for(int k = 0; k < 4; k++){
						double tmp[2];
						tmp[0] = qlg[j], tmp[1] = hlg[k];
						if(ok(tmp,2,tar)) {
							//cout << j << " " << k << endl;
							return 1;
						}
					}
				}
				bool cond = ok(szz+1,3,tar-szz[0]) ||
						ok(szz+1,3,szz[0]-tar) ||
						(szz[0]!=0 && ok(szz+1,3,tar/szz[0])) ||
						(tar!=0 && szz[0]!=0 && ok(szz+1,3,szz[0]/tar)) ||
						ok(szz,3,tar-szz[3]) ||
						ok(szz,3,tar+szz[3]) ||
						(szz[3]!=0 && ok(szz,3,tar/szz[3])) ||
						(szz[3]!=0 && ok(szz,3,tar*szz[3]));
				if(cond) return 1;
			}
			return 0;
		}
		default: return 0;
	}
}

double clearSr(double sr){
	return (double)((int)(sr+1e-6));
}

int main() {
	//double test[3] = {2,2,13};
	//cout << ok(test,3,24/13.0);
	while(1){
		cin >> shu[0];
		if(shu[0]<0) return 0;
		cin >> shu[1] >> shu[2] >> shu[3] >> tar;
		for(int i = 0; i < 4; i++) shu[i] = clearSr(shu[i]);
		tar = clearSr(tar);
		//printf("%.16lf %.16lf %.16lf %.16lf %.16lf\n", shu[0],shu[1],shu[2],shu[3],tar);
		cout << shu[0] << " " << shu[1] << " " << shu[2] << " " << shu[3] << " " << tar << " " << (ok(shu, 4, tar) ? "OK!" : "NO!") << endl;
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator