#include<iostream>usingnamespace std;constint N =2e5+10;int n, m;int a[N], b[N], c[N *2];intmain(){scanf("%d",&n);for(int i =0; i < n &&scanf("%d",&a[i]); i ++);scanf("%d",&m);for(int i =0; i < m &&scanf("%d",&b[i]); i ++);int k =0, i =0, j =0;while(i < n && j < m){if(a[i]< b[j]) c[k ++]= a[i ++];else c[k ++]= b[j ++];}while(i < n) c[k ++]= a[i ++];while(j < m) c[k ++]= b[j ++];cout << c[(n + m -1)/2];}
#include<iostream>usingnamespace std;intmain(){string s;getline(cin, s);int res =0;for(int i =0; i < s.size(); i ++){int l = i -1, r = i +1;while(i >=0&& r < s.size()&& s[l]== s[r]) l --, r ++;res =max(res, r -1-(l +1)+1);l = i, r = i +1;while(i >=0&& r < s.size()&& s[l]== s[r]) l --, r ++;res =max(res, r -1-(l +1)+1);}cout << res << endl;}
#include<iostream>#include<algorithm>usingnamespace std;constint N =1e5+10, INF =1e9;int n, m;int s[N];intmain(){scanf("%d%d",&n,&m);for(int i =1; i <= n &&scanf("%d",&s[i]); i ++) s[i]+= s[i -1];int res = INF;for(int i =1, j =1; i <= n; i ++){while(j +1<= i && s[i]- s[j +1-1]>= m) j ++;if(j <= i && s[i]- s[j -1]>= m) res =min(res, s[i]- s[j -1]);}for(int i =1, j =1; i <= n; i ++){while(j +1<= i && s[i]- s[j +1-1]>= m) j ++;if(j <= i && s[i]- s[j -1]== res)printf("%d-%d\n", j, i);}}
#include<iostream>usingnamespace std;constint N =1e5+10;int s[N];intmain(){int n;cin >> n;for(int i =1; i <= n; i ++) cin >> s[i], s[i]+= s[i -1];int m;cin >> m;while(m --){int l, r;cin >> l >> r;if(r < l)swap(l, r);cout <<min(s[r -1]- s[l -1], s[n]- s[r -1]+ s[l -1]);if(m !=0) cout << endl;}}
1048 Find Coins (25 分)
題意 :
給一序列,要求從中選出兩個值使得它們的和恰好等于m
#include<iostream>#include<algorithm>usingnamespace std;constint N =1e5+10;int n, m;int a[N];intmain(){scanf("%d%d",&n,&m);for(int i =0; i < n &&scanf("%d",&a[i]); i ++);sort(a, a + n);for(int i =0, j = n -1; i < n; i ++){while(a[i]+ a[j]> m && j > i) j --;if(j > i && a[i]+ a[j]== m){printf("%d %d\n", a[i], a[j]);return0;}}puts("No Solution");}
#include<iostream>#include<algorithm>usingnamespace std;constint N =1e5+10;int n, p;int a[N];intmain(){scanf("%d%d",&n,&p);for(int i =0; i < n &&scanf("%d",&a[i]); i ++);sort(a, a + n);int res =0;for(int l =0, r =0; r < n; r ++){while((longlong)a[l]* p < a[r]) l ++;res =max(res, r - l +1);}printf("%d", res);}
1117 Eddington Number (25 分)
題意 :
找最大的k,滿足序列中有k個數都超過k
#include<iostream>#include<algorithm>usingnamespace std;constint N =1e5+10;int a[N];intmain(){int n;scanf("%d",&n);for(int i =1; i <= n &&scanf("%d",&a[i]); i ++);sort(a +1, a + n +1);for(int i = n; i; i --)if(a[n - i +1]> i){printf("%d", i);return0;}printf("0");}
#include<iostream>usingnamespace std;constint N =110;int q[N];intjudge(int k,int i,int j)// 1為假話,0為真話{int t = q[k];if(t >0){if(t == i || t == j)return1;return0;}t =-t;if(t == i || t == j)return0;return1;}intmain(){int n;cin >> n;for(int i =1; i <= n; i ++) cin >> q[i];for(int i =1; i <= n; i ++)for(int j = i +1; j <= n; j ++){int s =0;s =judge(i, i, j)+judge(j, i, j);if(s !=1)continue;s =0;for(int k =1; k <= n; k ++)s +=judge(k, i, j);if(s !=2)continue;cout << i <<' '<< j;return0;}cout <<"No Solution";return0;}
#include<iostream>#include<stack>usingnamespace std;constint N =1e3+10;int m, n, k;int a[N];boolcheck(){stack<int> stk;for(int i =1, j =0; i <= n; i ++){stk.push(i);if(stk.size()> m)returnfalse;while(stk.size()&& stk.top()== a[j]) stk.pop(), j ++;}return stk.empty();}intmain(){scanf("%d%d%d",&m,&n,&k);while(k --){for(int i =0; i < n &&scanf("%d",&a[i]); i ++);if(check())puts("YES");elseputs("NO");}}與50位技術專家面對面20年技術見證,附贈技術全景圖