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的更多相关文章

  1. NOIP模拟17.9.21

    NOIP模拟17.9.21 3 58 145 201 161.5 样例输出21.6 数据规模及约定对于40% 的数据,N <= 20对于60% 的数据,N <= 1000对于100% 的数 ...

  2. NOIP模拟17.9.22

    NOIP模拟17.9.22 前进![问题描述]数轴的原点上有一只青蛙.青蛙要跳到数轴上≥

  3. NOIP模拟 17.8.20

    NOIP模拟17.8.20 A.阶乘[题目描述]亲爱的xyx同学正在研究数学与阶乘的关系,但是他喜欢颓废,于是他就制作了一个和阶乘有关系的数学游戏:给出两个整数 n,m,令 t = !n,每轮游戏的流 ...

  4. NOIP模拟 17.8.18

    NOIP模拟17.8.18 A.小菜一碟的背包[题目描述]Blice和阿强巴是好朋友但萌萌哒Blice不擅长数学,所以阿强巴给了她一些奶牛做练习阿强巴有 n头奶牛,每头奶牛每天可以产一定量的奶,同时也 ...

  5. NOIP模拟 17.8.15

    NOIP模拟17.8.15 A 债务文件名 输入文件 输出文件 时间限制 空间限制debt.pas/c/cpp debt.in debt.out 1s 128MB[题目描述]小 G 有一群好朋友,他们 ...

  6. NOIP模拟 17.8.17

    NOIP模拟17.8.17 A 小 G 的字符串文件名 输入文件 输出文件 时间限制 空间限制str.pas/c/cpp str.in str.out 1s 128MB[题目描述]有一天,小 L 给小 ...

  7. NOIP模拟 17.8.16

    NOIP模拟17.8.16 A 债务文件名 输入文件 输出文件 时间限制 空间限制debt.pas/c/cpp debt.in debt.out 1s 128MB[题目描述]小 G 有一群好朋友,他们 ...

  8. NOIP模拟 17.9.28

    公交车[问题描述]市内有

  9. Noip模拟17 2021.7.16

    我愿称这场考试为STL专练 T1 世界线 巧妙使用$bitset$当作vis数组使用,内存不会炸,操作还方便,的确是极好的. 但是这个题如果不开一半的$bitset$是会炸内存的,因为他能开得很大,但 ...

随机推荐

  1. JS 日期比较

    Js 日期比较方法 第一种方式 function compareDate(s1,s2){ return ((new Date(s1.replace(/-/g,"\/")))> ...

  2. parameter–precharge, tRCD and tRAS

    以下描述来自wikipeida : https://en.wikipedia.org/wiki/Synchronous_dynamic_random-access_memory 几点总结: (1) 每 ...

  3. thinkphp浏览历史功能实现方法

    这篇文章主要介绍了thinkphp浏览历史功能实现方法,可实现浏览器的浏览历史功能,是非常实用的技巧,需要的朋友可以参考下 本文实例讲述了thinkphp浏览历史功能实现方法,分享给大家供大家参考.具 ...

  4. html如何设置表格单元格内容垂直居中?

    父元素设置为表格的单元格元素td,而在表格单元格中的元素设置vertical-align: middle; 对父容器(td)使用:display: table-cell 其内子元素使用:vertica ...

  5. Ubuntu为什么远程连接不上

    因为没有安装ssh,输入以下命令, sudo apt-get install openssh-server openssh-client执行完再用xshell就可以连接上了

  6. boxFilter in opencv

    , -),bool normalize=true,int borderType=BORDER_DEFAULT) Smoothes image using box filter Parameters: ...

  7. 分享一个百度大牛的Python视频系列下载

    好像是百度资深大数据工程师 在录制Python视频课程讲课,包括Python基础入门.数据分析.网络爬虫.大数据处理.机器学习.推荐系统等系列,他还在不停地录制,课程感觉很不错,视频网盘分享给大家 学 ...

  8. JavaScript对象继承方式

    一.对象冒充 其原理如下:构造函数使用 this 关键字给所有属性和方法赋值(即采用类声明的构造函数方式).因为构造函数只是一个函数,所以可使 Parent 构造函数 成为 Children 的方法, ...

  9. 前端算法题:找出数组中第k大的数字出现多少次

    题目:给定一个一维数组,如[1,2,4,4,3,5],找出数组中第k大的数字出现多少次. 例如:第2大的数是4,出现2次,最后输出 4,2 function getNum(arr, k){ // 数组 ...

  10. 【xlwings1】多线程写入excel数据

    #!/ufr/bin/env python # -*- coding:utf-8 -*- import xlwings as xw import queue import threading impo ...