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 Ruby931031 at 2012-06-02 14:55:36 on Problem 3185
只要枚举第一个碗翻不翻,后面的每一个都是确定的。
O(1)的枚举量嘛~
#include <iostream>
using namespace std;
int bowl[25]={0},flip[25]={0};
int main()
{
	int i,cnt=100,tmp;
	for (i=1;i<21;i++)		cin >> bowl[i];

	flip[1] = tmp = 1;		//翻第一个
	for (i=2;i<21;i++)
		if ( flip[i] = (flip[i-2]^flip[i-1]^bowl[i-1]) )		tmp++;
	if ( tmp<cnt && (flip[19]^flip[20]^bowl[20])==0 )			cnt = tmp;


	flip[1] = tmp = 0;		//不翻第一个
	for (i=2;i<21;i++)
		if ( flip[i] = (flip[i-2]^flip[i-1]^bowl[i-1]) )		tmp++;
	if ( tmp<cnt  && (flip[19]^flip[20]^bowl[20])==0 )		cnt = tmp;
	cout << cnt << 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