洛谷P10904挖矿
- #include<bits/stdc++.h>
- using namespace std;
- int n, m;
- const int N = 2000010;
- int l[N], r[N];
- int cnt;
- int main(){
- cin >> n >> m;
- for(int i = 1; i <= n; i++){
- int x; cin >> x;
- if(x > 0){
- r[x]++;
- }
- else if(x < 0){
- l[-x]++;
- }
- else cnt = 1;
- }
- for(int i = 1; i < N; i++){
- l[i] += l[i - 1];
- r[i] += r[i - 1];
- }
- int ans = 0;
- for(int i = 0; i <= m; i++){
- int ll = l[i];
- if(m - 2 * i > 0){
- ll += r[m - 2 * i];
- }
- ans = max(ans, ll);
- int rr = r[i];
- if(m - 2 * i > 0){
- rr += l[m - 2 * i];
- }
- ans = max(ans, rr);
- }
- cout << ans + cnt << endl;
-
-
- return 0;
- }
复制代码 洛谷P
- #include<bits/stdc++.h>
- using namespace std;
- int n;
- bool check(string a, int cnt1, int cnt2){
- int l = cnt1, r = a.length() - 1 - cnt2;
- while(l < r){
- if(a[l] != a[r])return false;
- l++, r--;
- }
- return true;
- }
- bool check2(string b, string c){
- if(b.size() < c.size())return false;
- for(int i = c.size() - 1, j = b.size() - 1; i >= 0; i--, j--){
- if(c[i] != b[j])return false;
- }
- return true;
- }
- int main(){
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cin >> n;
- while(n--){
- string a;
- cin >> a;
- int cnt2 = 0, cnt1 = 0;
- string b = "";
- while(a[a.length() - 1 - cnt2] == 'l' || a[a.length() - 1 - cnt2] == 'q' || a[a.length() - 1 - cnt2] == 'b'){
- b += a[a.length() - 1 - cnt2];
- cnt2++;
- }
- string c = "";
- while(a[cnt1] == 'l' || a[cnt1] == 'q' || a[cnt1] == 'b'){
- c += a[cnt1];
- cnt1++;
- }
- if(check(a, cnt1, cnt2) && check2(b, c))cout << "Yes" << endl;
- else cout << "No" << endl;
- }
-
- return 0;
- }
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |