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

暴力搜索竟然也172ms AC了

Posted by czpmale at 2012-09-21 13:17:52 on Problem 2329
rt

真是不知道怎么dp才好

----------------------------------------------

#include <iostream>
#include <string>
#include <cstring>
#include <cmath> 
#include <cstdlib> 
#include <map> 
#include <algorithm> 
#include <vector> 
#include <stack>
#include <queue>
#include <set>
#include <iomanip> 
using namespace std;

//	cout<<fixed<<setprecision(1)
//	cout<<fixed<<setprecision(1)<<setw(n)

#define MAX 1000
int table[MAX][MAX];



int main()
{
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	
	int size;
	cin>>size;
	memset(table,0,sizeof(table)); 
	for(int i=2*size;i<=size*3-1;i++)
		for(int j=2*size;j<=size*3-1;j++)
			scanf("%d",&table[i][j]);
	
	for(int x=2*size;x<=size*3-1;x++)
		for(int y=2*size;y<=size*3-1;y++)
		{
			if(table[x][y]==0)
			{
				int non_zero_count=0,non_zero,flag=1;
				for(int i=1;i<size*2&&flag;i++)
				{
					for(int j=0;j<i;j++)
					{
						if(table[x+i-j][y+j]>0)
						{
							non_zero_count++;
							non_zero=table[x+i-j][y+j];
							flag=0;
						}
						if(table[x-i+j][y-j]>0)
						{
							non_zero_count++;
							non_zero=table[x-i+j][y-j];
							flag=0;
						}
						if(table[x-j][y+i-j]>0)
						{
							non_zero_count++;
							non_zero=table[x-j][y+i-j];
							flag=0;
						}
						if(table[x+j][y-i+j]>0)
						{
							non_zero_count++;
							non_zero=table[x+j][y-i+j];
							flag=0;
						}
					}
				}
				if(non_zero_count==1)
				{
					table[x][y]=-non_zero;
					continue;
				}
			}
		}
	
	

	for(int i=2*size;i<=size*3-1;i++)
	{ 
		for(int j=2*size;j<=size*3-1;j++)
		if(table[i][j]<0)
			printf("%d ",-table[i][j]);
		else
			printf("%d ",table[i][j]);
		printf("\n");
	} 
	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