cf 1006B (每日一嗑不能少)) 1006C

太,菜 ,了

这告诉我们要大胆尝试,小心求证

下标不是让你暴力的,是让你记录了直接减去的

掌握map和pair的用法,尽量熟练,加油

//  cf的B哦!仔细分析,不难的
//不要知难而退,对于任何事情都是,尤其是理科!
#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
//int a[2005];
int b[2005];
//map<int, int>m[2005];
int c[2005];
struct node{
	int a;
int flag;
}node[2005];
int main() {
	int n; int d; cin >> n >> d;
	for (int i = 1; i <= n; i++) {
		cin >> node[i].a;
		b[i] = node[i].a;
		node[i].flag = 0;
	}
	sort(b + 1, b + 1 + n);
	//b都已经sort过了
	//b是从小到大的
	int sum = 0;
	for (int i = n; i > n - d; i--) {
		//啊!!!!临界条件
		//如果有8天的话,最后就只剩下了5天啦
		sum = sum + b[i];
		for (int j = 1; j <= n; j++) {
			if (b[i] == node[j].a) { 
			node[j].flag = 1; 
			b[i] = 0;
			node[j].a = 0;//break;
			}
		}
		
	}
	cout << sum << endl;
	//最大的那么多... 先标注一下.... orx
	int record = 0;
	int summm = 0;
	for (int i = 1; i <= n; i++) {
		if (node[i].flag == 1) {
			c[summm] = i-record;//记录一下从多少个开始(也就是每一块有几个啦)
			record = i;
			summm++;//记录一下一共有了多少个块...
		}
	}
	//cout << c[1] + 1 << " ";
	//cout << summm << endl;
	for (int i = 0; i < summm-1; i++)cout << c[i]<<" ";
	cout << (c[summm-1] + (n - record)) << endl;
						   //.... 怎么又是一样的问题呀

	return 0;
}

.....

还有C  

先预处理一下 算出前缀数组 后缀数组

#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll a[200005];
ll before[200005];
ll after[200005];
int main() {
	int n; cin >> n; for (int i = 1; i <= n; i++)cin >> a[i];
	before[0] = 0;
	after[n] = a[n];
	for (int i = 1; i <= n; i++) { before[i] = before[i - 1] + a[i]; }
	for (int i = n - 1; i >= 1; i--) { after[i] = after[i + 1] + a[i]; }
	//求出前缀后缀数组之后,枚举后面的,如果前面的
	ll Max = 0;
	for (int i = 1; i <= n; i++)
	{
		ll pos = lower_bound(before + 1, before + 1 + n, after[i]) - before;
		if (pos < i && before[pos] ==after[i])
		{
			Max = max(Max, after[i]);

		}
	}
	cout << Max << endl;
	return 0;
}

注意lower_bound的用法。

不知道有重复 的行不行

===================

好。。  是不行的 我实验了一下-。-。

1 2 3 4  4 4 4 4 4 4 

4 4 4 4 4 4 4 4 虽然值是一样的4 但是pos是4 i是10  

每次都符合,每次都往后跑,但是这题里面lower-bound反正是能插入的最前面,  空  1 2 3  好歹2的序号是2 ,也能用。。

只是查找位置  并不是插入 海星。。。。div3什么lj题md

猜你喜欢

转载自blog.csdn.net/strongerirene/article/details/81160526