GYM 101604 || 20181010

看着前面咕咕咕的国庆集训 难受

十月十日要萌一天哇www

A.字符串

题意:给定一个字符串 问能否交换两个字符或者不交换字符,使其成为回文串

之前写的太丑 重写一遍加一堆 if 竟然过了w

思路:求出正序和倒叙有多少个不同的,根据不同的数量以及字符串长度(奇偶)判断。。

体验就是这种题要想好了再下笔。。(*下键盘

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
const int maxn = 500100;
char str[maxn];
int idx[3][2];
int main()
{
    scanf("%s", str);
    int len = strlen(str);
    int cnt = 0;
    for(int i = 0; i < (len>>1); i++)
    {
        if(cnt > 2) break;
        if(str[i] != str[len-1-i]) cnt++, idx[cnt-1][0] = str[i], idx[cnt-1][1] = str[len-1-i];
    }
    if(!cnt) printf("YES\n");
    else if(cnt > 2) printf("NO\n");
    else if(cnt == 1 && (len&1) && (idx[0][0]==str[len>>1] || idx[0][1]==str[len>>1])) printf("YES\n");
    else if(cnt == 1) printf("NO\n");
    else if((idx[0][0] == idx[1][1] && idx[0][1] == idx[1][0]) || (idx[0][0]==idx[1][0] && idx[0][1]==idx[1][1])) printf("YES\n");
    else printf("NO\n");//
    return 0;
}
View Code

B.贪心(?)

题意:坐标系中,起始位置(1, 1) ,有n张卡片,可以按不同顺序执行,卡片上写t, x, y, 分为两种,t == 1是向右走x步再向左走y步,  t == 2是向上走x步再向下走y步,到坐标轴就GG

思路:想一想可以发现(嗯我第一次就是因为没有想以为就是模拟wa了 zz难受)只要在横着和竖着移动的合能≥0,那么就可以有一种策略使它不能到坐标轴

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
const int maxn = 500100;
int main()
{
    int n;
    scanf("%d", &n);
    int x = 1, y = 1;
    bool ok = true;
    for(int i = 0; i < n; i++)
    {
        int t, xi, yi;
        scanf("%d%d%d", &t, &xi, &yi);
        if(t==1){
            x += xi;
            x -= yi;
        }
        if(t==2){
            y += xi;
            y -= yi;
        }
    }
    if(x <= 0 || y <= 0) printf("NO\n");
    else printf("YES\n(%d, %d)\n", x, y);
    return 0;
}
View Code

好困 留坑orz

猜你喜欢

转载自www.cnblogs.com/pinkglightning/p/9769868.html