5 条题解

  • 1
    @ 2023-9-9 14:53:47
    #include <iostream>
    #include <algorithm>
    using namespace std;
    int n, m, a[100005];
    int main() {
        freopen("sum.in", "r", stdin);
        freopen("sum.out", "w", stdout);
    	ios::sync_with_stdio(false);
    	cin.tie(nullptr), cout.tie(nullptr); 
        cin >> n;
        for (int i = 0; i < n; cin >> a[i++]);
        cin >> m;
        sort(a, a + n);
        for (int i = 0; i < n && a[i] <= m >> 1; i++)
            if (binary_search(a + i + 1, a + n, m - a[i])) {
                cout << a[i] << ' ' << m - a[i];
                return 0;
            }
        cout << "No";
        return 0;
    }
    
    • -24
      @ 2023-7-22 11:29:54
      #include <cstdio>
      #include <cctype>
      #include <algorithm>
      using namespace std;
      int n, m, a[100005], ans1 = -1, ans2, k;
      inline int read() {
      	int res = 0;
      	char c = getchar();
      	while (!isdigit(c))
      	    c = getchar();
      	while (isdigit(c)) {
      		res = (res << 3) + (res << 1) + (c - 48);
      		c = getchar(); 
      	}
      	return res;
      }
      int main() {
      	freopen("sum.in", "r", stdin);
      	freopen("sum.out", "w", stdout);
      	n = read();
      	for (int i = 0; i < n; i++)
      	    a[i] = read();
      	m = read();
      	sort(a, a + n);
      	for (int i = 0; i < n - 1 /* 纠正 */; i++) {
      		k = m - a[i];
      		if (binary_search(a, a + n, k)) {
      			ans1 = a[i], ans2 = k;
      			break;
      		}
      	}
      	if (ans1 == -1) printf("No");
      	else printf("%d %d", ans1, ans2);
      	return 0;
      }
      
      • -25
        @ 2023-7-24 15:44:23

        快踩我!!!!!!!!!!!!!!!!!!

        • -25
          @ 2023-7-24 15:43:51

          66666

          • -30
            @ 2023-7-22 11:01:05
            #include <cstdio>
            #include <cctype>
            #include <algorithm>
            using namespace std;
            int n, m, a[100005], ans1 = -1, ans2, k;
            inline int read() {
            	int res = 0;
            	char c = getchar();
            	while (!isdigit(c))
            	    c = getchar();
            	while (isdigit(c)) {
            		res = (res << 3) + (res << 1) + (c - 48);
            		c = getchar(); 
            	}
            	return res;
            }
            int main() {
            	freopen("sum.in", "r", stdin);
            	freopen("sum.out", "w", stdout);
            	n = read();
            	for (int i = 0; i < n; i++)
            	    a[i] = read();
            	m = read();
            	sort(a, a + n);
            	for (int i = 0; i < n; i++) {
            		k = m - a[i];
            		if (binary_search(a, a + n, k)) {
            			ans1 = a[i], ans2 = k;
            			break;
            		}
            	}
            	if (ans1 == -1) printf("No");
            	else printf("%d %d", ans1, ans2);
            	return 0;
            }
            
            • 1

            信息

            ID
            401
            时间
            1000ms
            内存
            256MiB
            难度
            8
            标签
            (无)
            递交数
            322
            已通过
            43
            上传者