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

优雅的暴力。。。。二进制

Posted by 2407_chensongkui at 2012-02-08 00:07:48 on Problem 1775
用二进制外加暴力做的 94ms...
没有其他那些暴力代码的那么多循环
但是WA了两次 为什么捏
第一次是while(cin>>n&&n=-1) 鄙视题目
第二次是while(cin>>n&&n<0) 没有本地运行就提交 我擦..鄙视自己

#include<iostream>
using namespace std;
bool  s[1000001];

void work()
{
	memset(s,false,sizeof(s));
	int i,j,t,temp[10],sum;
	temp[0]=1;
	for(i=1;i<=9;i++)
		temp[i]=i*temp[i-1];
	for(i=1;i<1024;i++)
	{
		sum=0;
		t=i;
		for(j=0;j<10;j++)
		{
			sum+=temp[9-j]*(t%2);
			t=t/2;
		}
		s[sum]=true;
	}
}

int main()
{
	int n;
	work();
	while(cin>>n&&n>=0)
	{
		if(s[n])
			cout<<"YES"<<endl;
		else
			cout<<"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