日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

poj2718 Smallest Difference

發布時間:2025/4/14 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 poj2718 Smallest Difference 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

思路:

暴力亂搞。

實現:

1 #include <iostream> 2 #include <cstdio> 3 #include <sstream> 4 #include <algorithm> 5 #include <vector> 6 #include <cmath> 7 using namespace std; 8 9 const int INF = 0x3f3f3f3f; 10 11 bool in[10]; 12 int t, n, num[10]; 13 string s; 14 stringstream ss; 15 int minn = INF; 16 17 int main() 18 { 19 cin >> t; 20 getchar(); 21 while (t--) 22 { 23 getline(cin, s); 24 ss.clear(); 25 n = 0; 26 minn = INF; 27 ss << s; 28 while (ss >> num[n++]); 29 n--; 30 if (n == 2) 31 { 32 cout << abs(num[0] - num[1]) << endl; 33 continue; 34 } 35 do 36 { 37 int x = 0, y = 0, z = 0; 38 for (int i = 0; i < n / 2; i++) 39 { 40 x += num[i]; 41 if (i != n / 2 - 1) 42 x *= 10; 43 } 44 for (int i = n / 2; i < n; i++) 45 { 46 y += num[i]; 47 if (i != n - 1) 48 y *= 10; 49 if (i == n / 2) 50 continue; 51 z += num[i]; 52 if (i != n - 1) 53 z *= 10; 54 } 55 if (!(n > 3 && num[0] == 0 || num[n / 2] == 0)) 56 minn = min(minn, abs(x - y)); 57 if (n & 1 && !(num[0] == 0 || n > 3 && num[n / 2 + 1] == 0)) 58 minn = min(minn, abs(x * 10 + num[n / 2] - z)); 59 } while (next_permutation(num, num + n)); 60 cout << minn << endl; 61 } 62 return 0; 63 }

?

轉載于:https://www.cnblogs.com/wangyiming/p/6581993.html

總結

以上是生活随笔為你收集整理的poj2718 Smallest Difference的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。