社区讨论

86分,其余全红

P1020[NOIP 1999 提高组] 导弹拦截参与者 1已保存回复 1

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
1 条
当前快照
1 份
快照标识符
@mhjdqxjf
此快照首次捕获于
2025/11/04 00:54
4 个月前
此快照最后确认于
2025/11/04 00:54
4 个月前
查看原帖
dp[i] 表示长度为 i 的不升子序列的最大结尾的相反数,g[i] 表示 第 i 个系统的 的最后一个导弹的高度
CPP
#include<bits/stdc++.h>
using namespace std;
inline int read();
inline void write(int x,bool op);
const int N = 1e5 + 5;
int k,n,a[N],b[N],dp[N],ans1,ans2,g[N];

signed main(){
//	while(k = read()){
//		a[++n] = k;
//		b[n] = -a[n];
//		dp[n] = 0x3f3f3f3f;
//	}
	while (true) {
		k = read();
		a[++n] = k;
		b[n] = -a[n];
		dp[n] = INT_MAX;
		g[n] = INT_MAX;
		char next = getchar();
		if (next == '\n' || next == EOF) break;
		ungetc(next, stdin);
	}
	 
	for (int i=1; i<=n; i++){
		int pos = upper_bound(dp+1,dp+1+n,b[i]) - dp;
		ans1 = max(ans1,pos);
		dp[pos] = b[i];
	}
	
	for(int i=1 ; i<=n; i++){
		int pos = upper_bound(g+1,g+1+n,a[i]) - g;
		ans2 = max(ans2,pos);
		g[pos] = a[i];
	}
	
	write(ans1,0);
	puts("");
	write(ans2,0);
	
	
	return 0;
}
inline int read(){
	int x = 0,f = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9'){
		if (ch == '-') f = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9'){
		x = (x << 1) + (x << 3) + ch - '0';
		ch = getchar();
	}
	return x * f;
}
char rec[21];
inline void write(int x,bool op){
	if (x == 0){
		putchar('0');
		return ;
	}
	if (x < 0){
		x = -x;
		putchar('-');
	}
	int p = 0;
	while(x){
		rec[p++] = x % 10 + '0';
		x /= 10;
	}
	while(p--){
		putchar(rec[p]);
	}
	if (op){
		putchar(' ');
	}
}

回复

1 条回复,欢迎继续交流。

正在加载回复...