我先在這里附上原題(擔心你們打不開這個網址,呵呵,校園網進OJ相當快):

In these days, Kinfkong likes to send mobile phone message to his girl friend Viorith in order to promote the friendship bewteen them. But after a while she is bored with him because his behavior often interferes with her busy study. Now Viorith sets a difficult problem about sending moble phone message for him. The problem is like this : There are n students in Viorith's class and each person has a private mobile phone. At first each person knows a piece of news and all of the news is different. In order to let all the students know the n pieces of news ,they can send message to their classmate by their mobile phone. When someone sends message to another one, he must send all the news which he knows. No Matter how many pieces news one have, he can send it at one time in a piece of mobile phone message. Viorith just want to know how many times should they send at least when all the students knows all the news.

If Kinfkong can't answer this question correctly, he will lose such a pretty and smart girl friend forever. How poor Kinfkong is! Can you help him? Just have a try.^_^??
(0<N<=2^31-1)

我想你們的英文水平一定比我高吧,我就不翻譯了。首先我那到這個題時,讀了一遍就首先想到是個(N-1)--則完全圖,很快就敲了一段代碼,sumbit了,是個WA(暈……),反過頭來又看了一遍原題( When someone sends message to another one, he must send all the news which he knows. No Matter how many pieces news one have, he can send it at one time in a piece of mobile phone message. ) 眼前一亮,想到線性正反向遍歷。1-2-3……n,先從正向1遍歷到n,然后在從n處遍歷1。sum=2*(n-1).
果然AC了!
參考代碼(比較簡單):

/*
??Name:
??Copyright:
??Author:?LonelyTree
??Date:?15-08-08?21:25
??Description:?1-2-3……n,先按這個順序正著遍歷一次,然后反著遍歷一次。
*/


#include
< stdio.h >
int ?main( void )
{
????
int ?count;
???unsigned?
long ? long ?sum,data;
????
// printf("%d",sizeof(?long?long));
????scanf( " %d " , & count);
????
while (count -- )
????
{
????????scanf(
" %llu " , & data);
????????sum
= 2 * (data - 1 );
????????printf(
" %llu\n " ,sum);
????}

????
return ? 0 ;
}

但是在實現我第一個想法時,出現了一個很奇怪的結果,題目限制是int的,(devcpp)
unsigned long long sum,data;(其實data最大是int型的)
我的一段代碼:
??????? scanf("%llu",&data);
??????? sum=data*(data-(unsigned long long)1);
??????? printf("%llu\n",sum);
可是我對data輸入的是987654321是這個,應該可以得出正確結果的,為什么輸出sum不對呢??
這段代碼,我讓網友運行了一下(vc2008)得出的正確的
我在機子上測試了unsigned long long的大小是8(64位)?


希望各位網友幫我解決一下!
??
?