NOIP模拟 17.8.14
NOIP模拟17.8.14
(天宇哥哥考察细心程度的题)
A 删除
文件名 输入文件 输出文件 时间限制 空间限制
del.cpp/c/pas del.in del.out 1s 512MB
【题目描述】
现在,我的手上有 n 个数字,分别是 a1, a2, a3, ..., an。
我现在需要删除其中的 k 个数字。当然我不希望随随便便删除,我希望删除 k
数字之后,剩下的 n − k 个数中有最多的不同的数。
【输入格式】
第一行两个正整数 n 和 k,含义如题目描述。
接下来一行,有 n 个非负整数,分别是 a1 到 an。
【输出格式】
一共一行,一个整数 ans,表示删除了 k 个数字后最多的不同的数的个数。
【样例输入】
4 1
1 3 1 2
【样例输出】
【样例解释】
如果删去第一个 1:
在[3,1,2]中有 3 个不同的数
如果删去 3:
在[1,1,2]中有 2 个不同的数
如果删去第二个 1:
在[1,3,2]中有 3 个不同的数
如果删去 2:
在[1,3,1]中有 1 个不同的数
【数据范围】
对于 30% 的数据,n ≤ 10,ai ≤ 10。
对于 60% 的数据,n ≤ 100,ai ≤ 100。
对于 80% 的数据,n ≤ 105,ai ≤ 105。
对于 100% 的数据,n ≤ 105,ai ≤ 109
【题解】
读错题,以为必须只出现一次才能被记入,还以为删除操作的次数<=k。。。作孽啊
很水的,排序,去重,直接减。我由于数次读错题,代码爆炸。
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <cstdlib>
- #include <algorithm>
- #include <set>
- const int INF = 0x3f3f3f3f;
- const int MAXN = + ;
- inline void read(int &x)
- {
- x = ;char ch = getchar(), c = ch;
- while(ch < '' || ch > '')c = ch, ch = getchar();
- while(ch <= '' && ch >= '')x = x * + ch - '', ch = getchar();
- if(c == '-')x = -x;
- }
- int n, num[MAXN], cnt, shu[MAXN], k, ans;
- int main()
- {
- read(n);read(k);
- for(register int i = ;i <= n;++ i)read(num[i]);
- std::sort(num + , num + + n);
- ++ cnt;++ ans;
- for(register int i = ;i <= n;++ i)
- if(num[i] == num[i - ])++shu[cnt];
- else if(shu[cnt])++shu[cnt], ++cnt, ++ans;
- else ++ans;
- if(shu[cnt])++shu[cnt];
- else --cnt;
- std::sort(shu + , shu + cnt + );
- register int i;
- for(i = ;i <= cnt;++ i)
- {
- if(k - shu[i] + < )
- {
- k = ;break;
- }
- else k -= shu[i] - ;
- }
- printf("%d", ans - k);
- return ;
- }
My T1
- #include <cstdio>
- #include <algorithm>
- using namespace std;
- const int MAXN = ;
- int n, m, k, a[MAXN];
- int main(){
- scanf("%d%d", &n, &k);
- for(int i = ; i <= n; ++ i) scanf("%d", &a[i]);
- sort(a + , a + + n);
- m = unique(a + , a + + n) - a - ;
- printf("%d\n", min(n - k, m));
- return ;
- }
Std T1
B 同花顺
文件名 输入文件 输出文件 时间限制 空间限制
card.cpp/c/pas card.in card.out 1s 512MB
【题目描述】
所谓同花顺,就是指一些扑克牌,它们花色相同,并且数字连续。
现在我手里有 n 张扑克牌,但它们可能并不能凑成同花顺。我现在想知道,最
少更换其中的多少张牌,我能让这 n 张牌都凑成同花顺?
【输入格式】
第一行一个整数 n,表示扑克牌的张数。
接下来 n 行,每行两个整数 ai 和 bi。其中 ai 表示第 i 张牌的花色,bi 表示第
i 张牌的数字。
【输出格式】
一行一个整数,表示最少更换多少张牌可以达到目标。
【样例输入 1】
5
1 1
1 2
1 3
1 4
1 5
【样例输出 1】
0
【样例输入 2】
5
1 9
1 10
2 11
2 12
2 13
【样例输出 2】
2
【数据范围】
对于 30% 的数据,n ≤ 10。
对于 60% 的数据,n ≤ 105,1 ≤ ai ≤ 105,1 ≤ bi ≤ n。
对于 100% 的数据,n ≤ 105,1 ≤ ai, bi ≤ 109
【题解】
再次理解错题。我以为 2 2 3 4 5也是同花顺。。。。于是没有去重。。
于是炸掉
正解是先去重,然后按花色排,花色相同按数字升序排。对每种花色,找一段[l,r],让其他牌插空,
使得num[r] - num[i] - 1 <= n - 2,这样答案就可以更新为min(ans, n - (r - l + 1))
这里显然可以用尺取法,然而我修改的时候,左端点是固定不动的,于是愉快的炸掉。。炸掉。。。
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <cstdlib>
- #include <algorithm>
- #define min(a, b) ((a) < (b) ? (a) : (b))
- const int INF = 0x3f3f3f3f;
- const int MAXN = + ;
- inline void read(int &x)
- {
- x = ;char ch = getchar(), c = ch;
- while(ch < '' || ch > '')c = ch, ch = getchar();
- while(ch <= '' && ch >= '')x = x * + ch - '', ch = getchar();
- if(c == '-')x = -x;
- }
- struct Node
- {
- int hua, num;
- Node(int _hua, int _num){hua = _hua;num = _num;}
- Node(){}
- }pai[MAXN];
- int n, ans;
- bool cmp(Node a, Node b)
- {
- return a.hua == b.hua ? a.num < b.num : a.hua < b.hua;
- }
- int main()
- {
- read(n);
- for(register int i = ;i <= n;++ i)read(pai[i].hua), read(pai[i].num);
- std::sort(pai + , pai + + n, cmp);
- register int p = ;
- for(register int i = ;i <= n;++ i)
- if(pai[p].hua != pai[i].hua || pai[p].num != pai[i].num)
- pai[++p].hua = pai[i].hua,pai[p].num = pai[i].num;
- register int now = pai[].hua, l = , ok = ;
- ans = n - ;
- for(register int i = ;i <= p;++ i)
- {
- if(pai[i].hua == now)
- {
- if(pai[i].num - pai[l].num - <= n - )
- ans = min(ans, n - (i - l + ));
- else
- {
- ans = min(ans, n - (i - l));
- while(pai[i].num - pai[l].num - > n - && l < i) ++ l;
- if(l <= i)ans = min(ans, n - (i - l + ));
- }
- }
- else
- now = pai[i].hua, l = i, ok = ;
- }
- printf("%d" ,ans);
- return ;
- }
My T2
- /*Orz gty big brother! 233*/
- #include <cstdio>
- #include <algorithm>
- using namespace std;
- const int MAXN = ;
- struct Cards{
- int a, b;
- bool operator < (const Cards& rhs) const{
- return a == rhs.a ? b < rhs.b : a < rhs.a;
- }
- bool operator == (const Cards& rhs) const{
- return a == rhs.a && b == rhs.b;
- }
- }cd[MAXN];
- int n, m;
- int solve(int s, int t){
- int i, j, ret = ;
- for(i = j = s; i <= t; ++ i){
- while(j < t && cd[j + ].b - cd[i].b < n) ++ j;
- ret = max(ret, j - i + );
- }
- return ret;
- }
- int main(){
- int i, j, ans = ;
- scanf("%d", &n);
- for(i = ; i <= n; ++ i)
- scanf("%d%d", &cd[i].a, &cd[i].b);
- sort(cd + , cd + + n);
- m = unique(cd + , cd + + n) - cd - ;
- for(i = , j = ; i <= m; ++ i)
- if(cd[i].a != cd[i - ].a){
- ans = max(ans, solve(j, i - ));
- j = i;
- }
- ans = max(ans, solve(j, i - ));
- printf("%d\n", n - ans);
- return ;
- }
Std T2
C 等式
文件名 输入文件 输出文件 时间限制 空间限制
equ.cpp/c/pas equ.in equ.out 2s 512MB
【题目描述】
我有 n 个式子
对于每一个式子,要么是 xi = xj 的形式,要么是 xi ̸= xj 的形式。
现在我给出这 n 个式子,你要告诉我,这 n 个式子是否可能同时成立。
【输入格式
每一个测试点有多组测试数据。
第一行有一个整数 T,表示测试数据的组数。
对于每一组测试数据,第一行包含一个正整数 n,表示式子的数目。
接下来 n 行,每行三个整数 i,j,e,描述一个式子。如果 e = 1,则这个式子
为 xi = xj。如果 e = 0,则这个式子是 xi ̸= xj。
【输出格式】
对于每一个测试数据输出一行。如果存在一种方案,使得所有的式子都被满足,
输出“YES”(不包含引号)。否则输出“NO”(不包含引号)。
【样例输入 1】
2
2
1 2 1
1 2 0
2
1 2 1
2 1 1
【样例输出 1】
NO
YES
【样例输入 2】
2
3
1 2 1
2 3 1
3 1 1
4
1 2 1
2 3 1
3 4 1
1 4 0
【样例输出 2】
YES
NO
【数据范围】
对于 20% 的数据,n ≤ 10。
对于 40% 的数据,n ≤ 100。
对于 70% 的数据,n ≤ 105,1 ≤ i, j ≤ 104。
对于 100% 的数据,n ≤ 105,1 ≤ i, j ≤ 109,1 ≤ t ≤ 10。
【题解】
离散化,先处理等号,并查集维护,然后看不等号,是否满足条件。竟然是NOI2015D1T1,NOI2015果然很水,,
唯一A了的一道题
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <cstdlib>
- #include <algorithm>
- const int INF = 0x3f3f3f3f;
- const int MAXN = + ;
- inline void read(int &x)
- {
- x = ;char ch = getchar(), c = ch;
- while(ch < '' || ch > '')c = ch, ch = getchar();
- while(ch <= '' && ch >= '')x = x * + ch - '', ch = getchar();
- if(c == '-')x = -x;
- }
- int t, n, fa[MAXN << ], num[MAXN << ], cnt[MAXN << ], e[MAXN];
- bool cmp(int a, int b)
- {
- return num[a] < num[b];
- }
- bool cmpp(int a, int b)
- {
- return e[a] > e[b];
- }
- int find(int x)
- {
- return fa[x] == x ? x : fa[x] = find(fa[x]);
- }
- int main()
- {
- read(t);
- for(;t;--t)
- {
- read(n);
- n <<= ;
- for(register int i = ;i <= n;i += )read(num[i]), read(num[i + ]), read(e[(i + )/]), cnt[i] = fa[i] = i, cnt[i + ] = fa[i + ] = i + ;
- std::sort(cnt + , cnt + + n, cmp);
- register int now = , pre = num[cnt[]], tmp;num[cnt[]] = now;
- for(register int i = ;i <= n;++ i)
- {
- tmp = num[cnt[i]];
- if(num[cnt[i]] != pre)++now;
- num[cnt[i]] = now;
- pre = tmp;
- }
- n >>= ;
- register int f1,f2;
- for(register int i = ;i <= n;++ i)
- {
- if(e[i])
- {
- f1 = find(num[(i << ) - ]), f2 = find(num[(i << )]);
- fa[f1] = f2;
- }
- }
- for(register int i = ;i <= n;++ i)
- {
- if(!e[i])
- {
- f1 = find(num[(i << ) - ]), f2 = find(num[(i << )]);
- if(f1 == f2)
- {
- printf("NO\n");
- goto L1;
- }
- }
- }
- printf("YES\n");
- L1: ;
- }
- return ;
- }
My T3
- #include <cstdio>
- #include <algorithm>
- using namespace std;
- const int MAXN = ;
- int u[MAXN], v[MAXN], e[MAXN], f[MAXN << ], n, tmp[MAXN << ];
- int find(int x){return x == f[x] ? x : f[x] = find(f[x]);}
- void merge(int x, int y){f[find(x)] = find(y);}
- void solve(){
- int i;
- scanf("%d", &n);
- for(i = ; i <= n * ; ++ i) f[i] = i;
- for(i = ; i <= n; ++ i){
- scanf("%d%d%d", &u[i], &v[i], &e[i]);
- tmp[i * - ] = u[i], tmp[i * ] = v[i];
- }
- sort(tmp + , tmp + + n * );
- for(i = ; i <= n; ++ i){
- u[i] = lower_bound(tmp + , tmp + + n * , u[i]) - tmp;
- v[i] = lower_bound(tmp + , tmp + + n * , v[i]) - tmp;
- if(e[i] && find(u[i]) != find(v[i])) merge(u[i], v[i]);
- }
- for(i = ; i <= n; ++ i){
- if(e[i]) continue;
- if(find(u[i]) == find(v[i])){
- printf("NO\n");
- return;
- }
- }
- printf("YES\n");
- }
- int main(){
- int testcase;
- scanf("%d", &testcase);
- while(testcase --)
- solve();
- return ;
- }
Std T3
【总结】
连续读错两道题愉快考炸了。。。本来是三道送分题。。。细节处理和审题还要加强。。
NOIP模拟 17.8.14的更多相关文章
- NOIP模拟17.9.21
NOIP模拟17.9.21 3 58 145 201 161.5 样例输出21.6 数据规模及约定对于40% 的数据,N <= 20对于60% 的数据,N <= 1000对于100% 的数 ...
- NOIP模拟17.9.22
NOIP模拟17.9.22 前进![问题描述]数轴的原点上有一只青蛙.青蛙要跳到数轴上≥
- NOIP模拟 17.8.20
NOIP模拟17.8.20 A.阶乘[题目描述]亲爱的xyx同学正在研究数学与阶乘的关系,但是他喜欢颓废,于是他就制作了一个和阶乘有关系的数学游戏:给出两个整数 n,m,令 t = !n,每轮游戏的流 ...
- NOIP模拟 17.8.18
NOIP模拟17.8.18 A.小菜一碟的背包[题目描述]Blice和阿强巴是好朋友但萌萌哒Blice不擅长数学,所以阿强巴给了她一些奶牛做练习阿强巴有 n头奶牛,每头奶牛每天可以产一定量的奶,同时也 ...
- NOIP模拟 17.8.15
NOIP模拟17.8.15 A 债务文件名 输入文件 输出文件 时间限制 空间限制debt.pas/c/cpp debt.in debt.out 1s 128MB[题目描述]小 G 有一群好朋友,他们 ...
- NOIP模拟 17.8.17
NOIP模拟17.8.17 A 小 G 的字符串文件名 输入文件 输出文件 时间限制 空间限制str.pas/c/cpp str.in str.out 1s 128MB[题目描述]有一天,小 L 给小 ...
- NOIP模拟 17.8.16
NOIP模拟17.8.16 A 债务文件名 输入文件 输出文件 时间限制 空间限制debt.pas/c/cpp debt.in debt.out 1s 128MB[题目描述]小 G 有一群好朋友,他们 ...
- NOIP模拟 17.9.28
公交车[问题描述]市内有
- Noip模拟17 2021.7.16
我愿称这场考试为STL专练 T1 世界线 巧妙使用$bitset$当作vis数组使用,内存不会炸,操作还方便,的确是极好的. 但是这个题如果不开一半的$bitset$是会炸内存的,因为他能开得很大,但 ...
随机推荐
- JavaScript数据可视化编程书籍上面的例子(flotr2)
先看demo再看例子 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...
- java的四个访问权限修饰符的作用范围
- leetcode算法题笔记|Reverse Integer
/** * @param {number} x * @return {number} */ var reverse = function(x) { var s; if(x<0){ s=-x; } ...
- spark dataframe 将null 改为 nan
由于我要叠加rdd某列的数据,如果加数中出现nan,结果也需要是nan,nan可以做到,但我要处理的数据源中的nan是以null的形式出现的,null不能叠加,而且我也不能删掉含null的行,于是我用 ...
- 你真的了解ES6的promise吗?
promise是一个构造函数,是用来解决ajax回调地狱的问题.axios就是用promise封装的.用于解决ajax请求时出现的回调地狱的问题.异步伴随回调. const p1 = new Prom ...
- 组件:slot插槽
<!DOCTYPE html> <html lang="zh"> <head> <title></title> < ...
- HDFS写数据的过程
- Puppet master-agent模型搭建
Puppet master-agent模型工作过程: 基于ssl xmlrpc进行通信,端口8140/tcp agent:默认每隔30分钟向master发送node name和facts,并请求cat ...
- 组合数学起步-排队[HNOI2012][BZOJ2729]
<题面> 这个题十分基础 写这个博客给自己看的呵呵 遇到这个题,一看就是组合数学, so,开始推公式, 刚开始想的是,先排男生,再排女生,最后排老师 推了一会,呃呃呃,情况复杂,考虑的好像 ...
- VMware 安装 ubuntu 后安装 VMWare tools
1.如果 VMware 的安装 VMWare tools 的菜单是灰色, 很可能原因是: 你的 cdrom 被占用着. 关闭系统, 编辑配置, 把cdrom 改为 自动检测. 即不要开始就加载一 ...