Hdu5174 --- Ferries Wheel
Note that the number of occurrences of each number should be recorded, and then the array should be sorted, de-duplicated, and calculated according to the meaning of the question. Note that int will overflow.
/*************************************** * *********************************> File Name: bc30-a.cpp> Author: ALex> Mail: zchao1995@gmail.com> Created Time: ******************************** **************************************** /# include# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include using namespace std; const double pi = acos (-1); const int inf = 0x3f3f3f3f; const double eps = 1e-15; typedef long LL; typedef pair
PLL; const LL mod = 2147483647; LL arr [111]; map
Re; int main () {int n; int icase = 1; while (~ Scanf ("% d", & n) {re. clear (); for (int I = 1; I <= n; ++ I) {scanf ("% I64d", & arr [I]); re [arr [I] ++;} printf ("Case # % d:", icase ++); sort (arr + 1, arr + 1 + n ); n = unique (arr + 1, arr + 1 + n)-arr-1; if (n = 1) {printf ("-1 \ n"); continue ;} int ans = 0; for (int I = 1; I <= n; ++ I) {if (I = 1) {if (arr [n] + arr [1]) % mod = arr [2]) {ans + = re [arr [1];} else if (I = n) {if (arr [n-1] + arr [n]) % mod = arr [1]) {ans + = re [arr [n];} else {if (arr [I-1] + arr [I]) % mod = arr [I + 1]) {ans + = re [arr [I] ;}} printf ("% d \ n", ans );} return 0 ;}