CodeForces #617(Div.3) 部分题解

Vitural Participate As a TEAM

A. Array with Odd Sum

题目大意:

简单判断即可。

AC代码:(By T)

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
 
int t;
int a[2005];
 
int main() {
	cin >> t;
	while (t--) {
		int n, sum = 0;
		cin >> n;
		int flag = 0;
		bool changable = false;
		for (int i = 1; i <= n; i++) {
			cin >> a[i];
			sum += a[i];
			if (!flag) flag = a[i];
			if ((flag % 2) ^ (a[i] % 2)) {
				changable = true;
			}
		}
		if (sum % 2 || changable) {
			printf("YES\n");
		} else {
			printf("NO\n");
		}
	}
	return 0;
}

 

B.Food Buying

 

题目大意:简单数学。满10对总数+1,那么只需要单独进行判断最后加上即可。

AC代码:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <stack>
#include <queue>
//#include <iomanip>
//#include <map>
//#include <time.h>
using namespace std;
typedef long long ll;
inline int read() {
    int x = 0;int f = 1; char c = getchar();
    while(c<'0' || c>'9') {if(c=='-') f = -f; c = getchar();}
    while(c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
    return x*f;
}
inline void write(int x) {
    if(!x)putchar('0');if(x<0)x=-x,putchar('-');
    static int sta[36];int tot = 0;
    while(x)sta[tot++]=x%10,x/=10;
    while(tot)putchar(sta[--tot]+48);
}
//mt19937 rnd(time(NULL));
const int inf = 0x3f3f3f3f;
const int maxn = 1000 + 10;
int T;
ll s;
int main() {
    cin >> T;
    while(T--) {
        cin >> s;
        ll ans = 0;
        ll tmp = s;
        while(tmp >= 10) {
            ans += tmp - tmp%10;
            tmp = tmp%10 + floor(tmp/10);
        }
        cout << ans + tmp << endl;
    }
    return 0;
}

 

C.Yet Another Walking Robot

 

题目大意:

一个机器人根据LRUD的指令进行移动,问能否删除一串最小字串使得其位置不变。

思路:

使用一个map<<int,int>,int>分别对应机器人的坐标和其对应的操作顺序。

使用map.count函数检查之前的坐标是否已经出现过。

同时由于要求最小的字串,因此还要整段扫描 求出最小值

尤其要注意下标与其的关系对应。

AC代码:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <stack>
#include <queue>
//#include <iomanip>
#include <map>
//#include <time.h>
using namespace std;
typedef long long ll;
inline int read() {
    int x = 0;int f = 1; char c = getchar();
    while(c<'0' || c>'9') {if(c=='-') f = -f; c = getchar();}
    while(c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
    return x*f;
}
inline void write(int x) {
    if(!x)putchar('0');if(x<0)x=-x,putchar('-');
    static int sta[36];int tot = 0;
    while(x)sta[tot++]=x%10,x/=10;
    while(tot)putchar(sta[--tot]+48);
}
//mt19937 rnd(time(NULL));
const int inf = 0x3f3f3f3f;
const int maxn = 1000 + 10;
int T;
map<pair<int,int>,int>m;
int main() {
    cin >> T;
 
    int n;
    while(T--) {
        m.clear();
        string s;
        cin >> n;
        cin >> s;
        int x = 0;
        int y = 0;
        int lpos = 0, rpos = 0;
        int sz = s.length();
        int ans = inf;
        m[{0,0}] = 0;
        for(int i = 0; i < sz; i++) {
            if(s[i] == 'L') {
                x--;
            }
            else if(s[i] == 'R') {
                x++;
            }
            else if(s[i] == 'U') {
                y++;
            }
            else if(s[i] == 'D') {
                y--;
            }
 
            pair<int,int> tmp = make_pair(x,y);
            if(m.count(tmp)) {
                if(ans > i - m[tmp] + 1) {
                    ans = i - m[tmp] + 1;
                    lpos = m[tmp] + 1;
                    rpos = i + 1;
                }
            }
            m[tmp] = i + 1;
        }
        if(ans == inf) cout << -1 << endl;
        else cout << lpos << " " << rpos << endl;
    }
    return 0;
}

E1. String Coloring (easy version)

(字串分割)?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值