UVa 10055 Hashmat the Brave Warrior
解題策略
看似簡單,的確也不難,只是有很基本的東西要注意。XDDD附上測資
0 4294967296
2 4294967296
0 4294967295
2 4294967295
這題測資剛好會超過int(long)的有效範圍,所以必須用 long long 或者 double。
閒聊
ACM真是有趣....而且殘酷....在最基本的地方栽跟頭,毫不留情。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
long long myabs(long long in) | |
{ | |
return (in >= 0) ? in : -in; | |
} | |
int main() | |
{ | |
long long hashmat, enemy; | |
while (scanf("%lld %lld ", &hashmat, &enemy ) == 2) | |
printf("%lld\n", myabs( enemy - hashmat ) ); | |
return 0; | |
} | |
g++的scanf/printf不吃long long
回覆刪除scanf/printf的語法是%ll
但g++不支援的樣子
目前找到唯一讓g++吃long long只有龜龜cin了 XD
http://yantchen.pixnet.net/blog/post/25674568
兩個版本都AC
但秒數差4倍
我剛剛解題成功了
回覆刪除關鍵
1. scanf/printf用"%lld"
2. 自己寫abs(),內建的不吃long long