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

很奇怪的事情,我用__int64是错的,int是对的

Posted by cx19860824 at 2007-04-27 13:45:21 on Problem 2309
我的程序用int时在处理大数的时候是来回溢得到正确答案,不过为什么int64不行,是不是测试数据给了负数啊...我试了半天,两个答案就是不一样(后面是我的代码,应该很简单,请知道问题的人赐教啊...ORZ...)
#include<stdio.h>
int x;
int t;
int main()
{
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&x);
		int c=0;
		while(!(x&1))
		{
			c++;
			x>>=1;
		}
		int a = x-1,b=x+1;
		__int64 e=x-1,d=x+1;
		if(a!=e||b!=d)while(1);//这里没有死循环
		a<<=c;
		b<<=c;
	/*	e<<=(__int64)c;
		d<<=(__int64)c;*/
		while(c--)
		{
			e=e*2;
			d=d*2;
		}	//原来以为是<<问题,改成这个还是不幸
		a++;
		b--;
		e++;
		d--;	
		if(a!=e||b!=d)while(1);//这里+了就TLE,明显两个处理的结果是不一样的,是编译器问题还是给了负数
		printf("%d %d\n",a,b);
	}
	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