2018校赛补题及反思

这次竟然如此多的省赛原题。。然而我全都忘掉了,看不懂看不懂,看懂了的不会做

被打成自闭,失去梦想变成咸鱼 //所以省赛的题没有补,题目记不起来了的也没补

补了两题很多人做出来的

1.最后一题求K个连续和最大的下标

这题对我来说并没有很简单啊,回来还是写了一个多小时emmmmm,所以没有很可惜
可是为什么别人能当场做出来呢,气死我了

结论:

1/样例模拟一定要自动地全面考虑,尤其是负数,0,无解(k比n大), 没有意义的情况。。

2/。在技术还不行的时候不能有   想使空间复杂度最小   的洁癖。

(不熟练怎么用结构体类型的vector,为什么非得用vector呢。。)

附上午写的经过自己测验多种类型样例没有WA的。。

/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <numeric>
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;

// int i;
// LL sum;
// struct P {				//不熟练怎么用结构体类型的vector,为什么非得用vector呢
// 	int index;
// 	LL s;
// 	P(int index = 0, LL s = 0) : index(i), s(sum) {}

// 	bool operator > (const P& a) const {

// 		return a.s < s;
// 	}
// };
// vector<int> v;
// vector<P> h;
const int maxn = 100000 + 24;
vector<int> v;
LL s[maxn];

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	int k, x;
	//这题对我来说并没有很简单啊,回来还是写了一个多小时emmmmm,所以没有很可惜
	//可是为什么别人能当场做出来呢
	
	//样例模拟一定要自动地全面考虑,尤其是负数,0,无解(k比n大), 没有意义的情况
	char ch;
	while(scanf("%d", &k) == 1) {
			v.clear();
			LL sum, res = -10000;
			int flag = 1;
			sum = 0;
			getchar();
			// while(scanf("%c", &ch) != EOF && ch != '#') {
			// 	x = ch - '0';	//这样是不行的,因为如果是负数...
			// 	v.push_back(x);
			// 	getchar();
			// }
			while(scanf("%d", &x) == 1) {
				v.push_back(x);
			}
			getchar();//这个是为了清除输入缓冲区的getchar(),否则就会不能实现多组输入输出
			int n = v.size();
			// for(int i = 0; i < n; i++) {
			// 	cout << v[i] << " ";
			// }
			// cout << endl;
			if(k <= 0)	cout << "-1" << endl;
			else if(k == 1)	{
				int _max = -10000;
				for(int i = 0; i < n; i++) {
					_max = max(_max, v[i]);
				}
				cout << _max << endl;
			}
			else if(k > n) {
				cout << "-1" << endl;
				//break;
			}
			else if(k == n) {
				cout << "0" << endl;
				//break;
			}
			else {
				for(int i = 0; i < n - k + 1; i++) {
					sum = 0; 
					// for(int j = 0; j < k; j++) {
					// 	sum += v[i+j];
					// }
					sum = accumulate(v.begin() + i, v.begin() + i + k, 0);
					s[i] = sum;
					res = max(res, sum);
					//cout << res << "\t" << sum << endl;
				}
				
				for(int i = 0; i < n - k + 1; i++) {
					if(s[i] == res) {
							if(flag) {
								cout << i+1;
								flag = 0;
							}
							else	cout << " " << i+1;
					}
				}
			}	
	}
	return 0;
}
/**/

2.贪心的那题,,当场就发现跟hdu2037解题方法,甚至可以说AC代码都一模一样。。然而,,我不知道当时为什么就是WA了到最后都没能AC。

上午一把过了,真是神奇。

/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>

typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
const int maxn = 100000 + 24;

struct P {
	int s, e;
	P(int s = 0, int e = 0) : s(s), e(e) {}

	bool operator < (const P& a) const {
		return e < a.e;
	}
};

P p[maxn];
int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	int k;
	while(cin >> k && k) {
		int i, s, e;
		for(i = 0; i < k; i++) {
			cin >> s >> e;
			p[i].s = s, p[i].e = e;
		}
		sort(p, p + k);
		int cnt = 1, t = p[0].e;
		for(i = 1; i < k; i++) {
			if(p[i].s >= t) {
				cnt++;
				t = p[i].e;
			}
		}
		cout << cnt << endl;
	}
	return 0;
}
/**/

 究其根本原因,可能是很久没有使用结构体了,很生疏;

唉,还是要各种题型都练,还要训练好思维方式。

记得还有一题排序算weight的,疑似组合数学,,然而看了一会根本想不出思路。。放弃了放弃了,枉我还借了一本组合数学的书假装学了几天combinatorial mathematics

中文题一道都没做出来,尴尬

(字体不知道为何如此小。。)

以上,就是我挂机四个半小时的全描述。

猜你喜欢

转载自blog.csdn.net/wen__han/article/details/83472956