注意一个坑,就是当M是偶数的时候可能有两个M >> 1的值,这种时候就只能数数了..
1 #include <iostream> 2 #include <vector> 3 #include <string> 4 #include <fstream> 5 6 using namespace std; 7 8 #define OJ 9 10 #ifdef OJ 11 #define fin cin 12 #else 13 ifstream fin("in.data"); 14 #endif 15 16 int main(){ 17 int N, M, n; 18 fin >> N >> M; 19 20 vector<int> money(1001, 0); 21 for (int i = 0; i < N; i++){ 22 fin >> n; 23 if (n >= M) continue; 24 money[n]++; 25 } 26 27 int half_M = (M >> 1) + 1; 28 for (int i = 1; i < half_M; i++){ 29 if (money[i] > 0) 30 money[i]--; 31 else 32 continue; 33 if (money[M - i] > 0){ 34 cout << i << " " << M - i << endl; 35 return 0; 36 } 37 } 38 39 cout << "No Solution" << endl; 40 41 return 0; 42 }
时间: 2024-10-21 01:48:22