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

这么个水题de了好久的bug,就一个continue写成了break。。。暴力+剪枝,32ms

Posted by KatrineYang at 2016-11-13 12:50:02 on Problem 1497
#include <iostream>
#include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
using namespace std;

int prm[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,0,1,3},{2,0,3,1},{2,1,0,3},{2,1,3,0},{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}};

int main() {
	char mlc[4][15];
	while(1){
		scanf("%s", mlc[0]);
		if(strlen(mlc[0]) < 12) break;
		scanf("%s%s%s",mlc[1],mlc[2],mlc[3]);
		int mj = 0;
		for(int pl = 0; pl < 24; pl++){
			if(mj == 64) break;
			char *s0 = mlc[prm[pl][0]], *s1 = mlc[prm[pl][1]], *s2 = mlc[prm[pl][2]], *s3 = mlc[prm[pl][3]];
			//printf("pl=%d\n", pl);
			//printf("%s %s %s %s\n", s0, s1, s2, s3);
			for(int i = 1; i <= 8; i++){
				if((9-i)*8<=mj) break;
				for(int j = 10; j >= i+2; j--){
					if((j-i-1)*8<=mj) break;
					for(int k = 1; k <= 10-(j-i); k++){
						char c1 = s0[i], c2 = s1[k], c3 = s0[j], c4 = s1[k+j-i];
						//printf("%d %d %d %c%c%c%c\n", i,j,k,c1,c2,c3,c4);
						for(int jg = 9; jg >= 2; jg--){
							if((j-i-1)*(jg-1)<=mj) break;
							//printf("jg=%d\n",jg);
							bool k2 = 0;
							for(int s = 1; s <= 10-jg; s++){
								if(s2[s]==c1 && s2[s+jg]==c2){
									k2 = 1;
									break;
								}
							}
							if(!k2)continue;
							for(int t = 1; t <= 10-jg; t++){
								if(s3[t]==c3 && s3[t+jg]==c4){
									int nmj = (j-i-1)*(jg-1);
									if(nmj>mj)mj=nmj;
									break;
								}
							}
						}
					}
				}
			}
		}
		printf("%d\n",mj);
	}
	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