码迷,mamicode.com
首页 > 其他好文 > 详细

CF #640 (div4)

时间:2020-05-28 16:51:37      阅读:57      评论:0      收藏:0      [点我收藏+]

标签:oid   mem   i++   cti   str   ems   using   move   ret   

CF640 div4

草 迟到半个月的补题

真正的懒狗

再懒就无了

  • D. Alice, Bob and Candies

    题意:n个数字,奇数时间从左侧删数字,偶数时间从右侧删数字,每次删的数字之和必须大于上次的。问最多删多少次和左边删除数字和与右边删除数字和。
    题解:很简单的模拟题,初始情况特判即可,不知道当时为什么没做出来??

#include<iostream>

using namespace std;
int can[1005];
int main() {
	int t;
	cin >> t;
	while (t--) {
		int n;
		int a=0, b=0;
		cin >> n;
		for (int i = 1; i <= n; i++) {
			cin >> can[i];
		}
		int moves = 0;
		int l = 1, r = n,sum=0;
		while (l<=r) {
			++moves;
			if (moves % 2 == 1) {
				if (moves == 1) {
					sum = can[l++];
					a+=sum;
				}
				else {
					int tmp = 0;
					while (tmp < sum + 1&&l<=r) {
						tmp += can[l++];
					}
					sum = tmp;
					a += sum;
					if (l > r) {
						break;
					}
				}
			}
			else {
				int tmp = 0;
				while (tmp < sum + 1 && l <= r) {
					tmp += can[r--];
				}
				sum = tmp;
				b += sum;
				if (l > r) {
					break;
				}
			}
		}
		cout << moves << " " << a << " " << b << endl;

	}
}
  • E.Special Elements

    题意:问一组数中有多少个数可以表示成数组的区间和。
    题解:前缀和

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int a[8010], sum[8010], num[8010];
int main() {
	int t;
	cin >> t;
	while (t--) {
		
		int cnt = 0;
		int n;
		cin >> n;
		for (int i = 1; i <= n; i++) {
			cin >> a[i];
			num[a[i]]++;
			sum[i] = sum[i - 1] + a[i];
		}

		for (int i = 1; i <= n; i++) {
			for (int j = i + 1; j <= n; j++) {
				int tmp = sum[j] - sum[i-1];
				if (tmp <= n && num[tmp] > 0) {
					cnt += num[tmp];
					num[tmp] = 0;
				}
			}
		}
		memset(num, 0, sizeof(num));
		cout << cnt << endl;
	}
}
  • F. Binary String Reconstruction

    题意:01串 \(n_0\)代表00个数,\(n_1\)代表\(10或01\)个数,\(n_2\)代表\(11\)个数。t次询问求合法串。
    题解:又是模拟

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

int main() {
	int t;
	cin >> t;
	while (t--) {
		int a, b, c;
		string s1, s2, s3;
		cin >> a >> b >> c;
		if(a > 0) {
			int tmp = a + 1;
			while (tmp--) {
				s1 += "0";
			}
		}
		
		if (a == 0&&b>0) {
			s2 += "0";
		}
		if (c > 0) {
			b--;
		}
		if (b > 0) {
			s2 += "1";
			b--;
			int cnt = 0;
			while (b--) {
				if (cnt % 2 == 0)
					s2 += "0";
				else
					s2 += "1";
				cnt++;
			}
		}
		if (c > 0) {
			int tmp = c + 1;
			while (tmp--) {
				s3 += "1";
			}
		}
		string res = s3 + s1 + s2;
		cout << res << endl;
	}
}
  • G. Special Permutation
    题意题解懒得写了,还是模拟
#include<iostream>
#include<stack>
#include<cstring>
using namespace std;
int ac[6] = { -4,-3,-2,2,3,4 };
int flag = 0;
int vis[1005];
stack<int> s;
int n;
void dfs(int x) {
	if (flag == 1) return;
	if (s.size() == n) {
		while (!s.empty()) {
			cout << s.top() << " ";
			s.pop();
		}
		cout << endl;
		flag = 1;
		return;
	}

	for (int i = 0; i <= 5; ++i) {
		int tmp = x + ac[i];
		if (tmp <= 0 || tmp > n||vis[tmp]) {
			continue;
		}
		vis[tmp] = 1;
		s.push(tmp);
		dfs(tmp);
		if (flag == 1) return;
		vis[tmp] = 0;
		s.pop();
	}
	
}
int main() {
	int t;
	cin >> t;
	while(t--) {
		cin >> n;
		for (int i = n; i >0; --i) {	
			vis[i] = 1;
			s.push(i);
			dfs(i);
			if (flag) {
				break;
			}
			vis[i] = 0;
			s.pop();
		}
		if (flag == 0) {
			cout << -1 << endl;
		}
		flag = 0;
		while (!s.empty()) {
			s.pop();
		}
		memset(vis, 0, sizeof(vis));
	}
}

现在回头一看都是rz题,为啥当时不敢写呢

CF #640 (div4)

标签:oid   mem   i++   cti   str   ems   using   move   ret   

原文地址:https://www.cnblogs.com/Cha2azzZ/p/12981343.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!