NOIP2020总结

总结

T1 : 打了 b f s bfs bfs,没用高精度(感觉高精度会T)

T2:不知道在想什么,,明明只用Hash就能A,,,我不仅没搞出正解,全为一个字母的分都没骗,,明明有一点思路,当时就是想不出来,,浪费了很多时间

而且万一我那个sb暴力退化到了 O ( n 3 ) O(n^3) O(n3)(对,你没看错,就是 O ( n 3 ) O(n^3) O(n3)),T2暴力的分就没了,,

T3:暴力没打,,搞sbT2、T4

T4 : 暴力,应该 p t s   40 pts\ 40 pts 40

T2sb题没打出来算是一个遗憾了。

话说NOIP竟然考了字符串/xk

估分: 100 + 48 + 0 + 40 = 188 100+48+0+40=188 100+48+0+40=188

信奥题库: 100 + 48 + 0 + 10 = 158 100+48+0+10=158 100+48+0+10=158 T 4 T4 T4 剩下 30 p t s   W A 30pts\ WA 30pts WA 了。。。

R e s u l t :   80 + 48 + 0 + 5 = 133 Result:\ 80+48+0+5=133 Result: 80+48+0+5=133

真心不该考这么点,,,

也没有关系,以后努力将知识变深变宽,,加油!

D o n ′ t   w o r r y .   T h e   f u t u r e   i s   b r i g h t . I   s h o u l d   j u s t   s i n g   t h e   s o n g   o f   t h e   s t a r   a n d   s k y . Don't\ worry.\ The\ future\ is\ bright. I\ should\ just\ sing\ the\ song\ of\ the\ star\ and\ sky. Dont worry. The future is bright.I should just sing the song of the star and sky.

题解

T1:要打高精,当然可以用 d o u b l e double double 水过去,注意先除 g c d gcd gcd 再乘。

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;
const int MAXN = 1e5 + 5;
const double eps = 1e-20;
struct Node {
	double Val;
	int Num;
};
int n, m, p, d[MAXN], Size, Y;
double ans_x[MAXN], ans_y[MAXN], G;
bool vis[MAXN];
vector <int> v[MAXN];
queue <Node> que;
Node t, q, r;
void read(int &x) {
	x = 0;
	bool f = 1;
	char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = 0;
		c = getchar();
	}
	while(c >= '0' && c <= '9') {
		x = (x << 1) + (x << 3) + (c - '0');
		c = getchar();
	}
	x = f ? x : -x;
}
double Gcd(double x, double y) {
	if(x < y) swap(x, y);
	if(y < eps) return x;
	return Gcd(y, x - floor(x / y) * y);
}
void bfs() {
	while(!que.empty()) {
		t = que.front(); que.pop();
		Size = v[t.Num].size();
		t.Val *= Size;
		for(int i = 0; i < Size; i ++) {
			Y = v[t.Num][i];
			if(vis[Y]) {
				if(ans_x[Y] == 0 || ans_y[Y] == 0) {
					ans_x[Y] = 1; ans_y[Y] = t.Val;
					continue;
				}
				G = Gcd(ans_y[Y], t.Val);
				double fuck = ans_y[Y] / G * t.Val;
				ans_x[Y] = fuck / ans_y[Y] * ans_x[Y] + fuck / t.Val * 1;
				ans_y[Y] = fuck;
				G = Gcd(ans_x[Y], ans_y[Y]);
				ans_x[Y] /= G; ans_y[Y] /= G;
				continue;
			}
			q.Num = Y; q.Val = t.Val;
			que.push(q);
		}
	}
}
int main() {
//	freopen("water.in", "r", stdin);
//	freopen("water.out", "w", stdout);
	int x;
	read(n); read(m);
	for(int i = 1; i <= n; i ++) {
		read(p);
		if(p == 0) vis[i] = 1;
		for(int j = 1; j <= p; j ++) {
			read(x);
			v[i].push_back(x);
		}
	}
	for(int i = 1; i <= m; i ++) {
		t.Num = i; t.Val = 1; que.push(t);
	}
	bfs();
	for(int i = 1; i <= n; i ++) {
		if(vis[i]) printf("%.0lf %.0lf\n", ans_x[i], ans_y[i]);
	}
	return 0;
}

T2:枚举循环节所在位置,再倍增, H a s h Hash Hash 判相等,注意这个性质:奇数个数最多不大于 26 26 26 个,所以可以预处理,考场上就是没注意到这个性质,导致再用了 O ( n ) O(n) O(n) 判断奇数个数。还是多做点思维题学一点奇怪的技巧吧。。
但似乎这个代码 c + + ( n o i ) c++(noi) c++(noi) 过不了(luogu 没开 O 2 O_2 O2 都能过),有空学学 O ( n ) O(n) O(n) 的做法吧。。

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#define LL long long
#define uLL unsigned long long
using namespace std;
const int MAXN = 1100000;
long long ans;
int t, q, r, len, T, pre[MAXN], suf[MAXN], fuck[28], maxx, cnt;
bool C[55];
char s[MAXN];
uLL Hash[MAXN], P[MAXN];
int main() {
//	freopen("string.in", "r", stdin);
//	freopen("string.out", "w", stdout);
	scanf("%d", &T);
	while(T --) {
		scanf("%s", s + 1);
		len = strlen(s + 1);
		ans = 0; maxx = 0;
		P[0] = 1;
		for(int i = 1; i <= len; i ++) {
			Hash[i] = Hash[i - 1] * 1331 + s[i] - 'a' + 1;
			P[i] = P[i - 1] * 1331;
			if(s[i] > maxx) maxx = s[i];
		}
		maxx -= 'a' + 1;
		memset(C, 0, sizeof(C));
		suf[len + 1] = 0;
		for(int i = len; i >= 1; i --) {
			C[s[i] - 'a'] ^= 1; suf[i] = suf[i + 1];
			if(C[s[i] - 'a']) suf[i] ++;
			else suf[i] --;
		}
		memset(C, 0, sizeof(C));
		memset(fuck, 0, sizeof(fuck));
		C[s[1] - 'a'] ^= 1; cnt = 1;
		for(int i = cnt; i <= maxx; i ++) fuck[i] ++;
		for(int i = 2; i < len; i ++) {
			for(int j = i; j < len; j += i) {
				if(Hash[j] - Hash[j - i] * P[i] == Hash[i]) ans += fuck[suf[j + 1]];
				else {
					break;
				}
			}
			C[s[i] - 'a'] ^= 1;
			if(C[s[i] - 'a']) cnt ++;
			else cnt --;
			for(int i = cnt; i <= maxx; i ++) fuck[i] ++;
		}
		printf("%lld\n", ans);
	}
	return 0;
}

T3:思维题,我是看了题解,学了大概的思路才开始打的,确实不好想,细节很多,需要自己慢慢调。先考虑两根柱子,假设有黑白两种颜色,定义第一根柱子黑色的个数为 s s s,推一推可发现(这里略过程),可以用 O ( 2 m + s ) O(2m+s) O(2m+s) 的复杂度将第一根柱子上的黑白球整理好(并且第二根柱子不变),之后显然。考虑 n > 2 n>2 n>2 的情况,收到前面做法的启发,可以将一半的颜色染成黑色,一半染成白色。再按照刚才的做法做,那我们如何让第 x x x 根柱子全是一种颜色呢?显然,可以用大约 O ( 2 m + s ) O(2m+s) O(2m+s) 的时间全是一种颜色,详细见代码,总时间 O ( n × l o g 2 n × O ( 4 m + 2 s ) ) O(n\times log_2n\times O(4m+2s)) O(n×log2n×O(4m+2s)),可以过。

// ——Star Sky.
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <climits>
#include <stack>
using namespace std;
const int MAXN = 55, MAXM = 405, MAXP = 820005;
int len[MAXN], Color[MAXN][MAXM], cw[MAXN], cb[MAXN];
int n, m, mp[MAXM], tot, gx[MAXP], gy[MAXP], C[MAXN], cnt, cntw, cntb;
int qaq[MAXN];
void Move(int x, int y) {//移动 
	gx[++ tot] = x; gy[tot] = y;
	Color[y][++ len[y]] = Color[x][len[x] --];
}
void Clac(int x) {
	C[x] = 0;
	for(int i = 1; i <= len[x]; i ++) {
		C[x] += mp[Color[x][i]];
	}
}
void Change(int x, int y) {//利用 y将 x整理好
	Clac(x); Clac(y);
	for(int i = 1; i <= C[x]; i ++) Move(y, n + 1);
	for(int i = m; i >= 1; i --) {
		if(!mp[Color[x][i]]) Move(x, n + 1);
		else Move(x, y);
	}
	for(int i = 1; i <= m - C[x]; i ++) Move(n + 1, x);
	for(int i = 1; i <= C[x]; i ++) Move(y, x);
	for(int i = 1; i <= C[x]; i ++) Move(n + 1, y);
}
void Apple(int x, int y) {//让 x上全是一种颜色 
	Clac(x); Clac(y);
	if(C[x] + C[y] >= m) {//让 x上全是黑 
		for(int i = 1; i <= m; i ++) Move(x, n + 1);
		for(int i = 1; i <= C[y]; i ++) Move(y, x);
		for(int i = 1; i <= m - C[x]; i ++) Move(n + 1, y);
		for(int i = 1; i <= m - C[y]; i ++) Move(n + 1, x);
		for(int i = 1; i <= C[x] + C[y] - m; i ++) Move(n + 1, y);
		cb[++ cntb] = x;
	}
	else {//让 x上全是白 
		for(int i = 1; i <= C[x]; i ++) Move(x, n + 1);
		for(int i = 1; i <= C[y]; i ++) Move(y, n + 1);
		for(int i = 1; i <= C[x]; i ++) Move(y, x);
		for(int i = 1; i <= C[x] + C[y]; i ++) Move(n + 1, y);
		cw[++ cntw] = x;
	}
}
void dfs(int qwq[], int Q, int l, int r) {
	if(Q <= 1) return;
	int mid = (l + r) >> 1;
	cnt = 0; cntw = 0; cntb = 0;
	for(int i = l; i <= mid; i ++) mp[i] = 0;
	for(int i = mid + 1; i <= r; i ++) mp[i] = 1;
	for(int i = 1; i <= Q; i ++) {//每根柱黑白整理 
		if(qwq[i] != 1) Change(qwq[i], 1);
		else Change(1, qwq[2]);
	}
	for(int i = 1; i < Q; i ++) {
		Apple(qwq[i], qwq[i + 1]);
	}
	if(mp[Color[qwq[Q]][1]]) cb[++ cntb] = qwq[Q];
	else cw[++ cntw] = qwq[Q];
	int fuck[MAXN], cntbb = cntb;
	for(int i = 1; i <= cntbb; i ++) fuck[i] = cb[i];
	dfs(cw, cntw, l, mid);
	dfs(fuck, cntbb, mid + 1, r);
}
int main() {
//	freopen("ball3.in", "r", stdin);
//	freopen("ball3.txt", "w", stdout);
	int x;
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i ++) {
		for(int j = 1; j <= m; j ++) {
			scanf("%d", &x);
			Color[i][++ len[i]] = x;
		}
	}
	for(int i = 1; i <= n; i ++) qaq[i] = i;
	dfs(qaq, n, 1, n);
	printf("%d\n", tot);
	for(int i = 1; i <= tot; i ++) {
		printf("%d %d\n", gx[i], gy[i]);
	}
	return 0;
}

T4:有空再做。。。难。。。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值