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. Grep- Linux必学的60个命令

    1.作用 grep命令可以指定文件中搜索特定的内容,并将含有这些内容的行标准输出.grep全称是Global Regular Expression Print,表示全局正则表达式版本,它的使用权限是所 ...

  2. T2988 删除数字【状压Dp+前缀和优化】

    Online Judge:从Topcoder搬过来,具体哪一题不清楚 Label:状压Dp+前缀和优化 题目描述 给定两个数A和N,形成一个长度为N+1的序列,(A,A+1,A+2,...,A+N-1 ...

  3. 系统负载load

    一.查看系统负荷 如果你的电脑很慢,你或许想查看一下,它的工作量是否太大了. 在Linux系统中,我们一般使用uptime命令查看(w命令和top命令也行).(另外,它们在苹果公司的Mac电脑上也适用 ...

  4. 一个班六个人,学号语文、数学、英语,接收成绩(不接受学号),输出学号成绩,总分、平均分,按总分排序(原生JS)

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  5. Flink中的多source+event watermark测试

    这次需要做一个监控项目,全网日志的指标计算,上线的话,计算量应该是百亿/天 单个source对应的sql如下 最原始的sql select pro,throwable,level,ip,`count` ...

  6. Leetcode551.Student Attendance Record I学生出勤记录1

    给定一个字符串来代表一个学生的出勤纪录,这个纪录仅包含以下三个字符: 'A' : Absent,缺勤 'L' : Late,迟到 'P' : Present,到场 如果一个学生的出勤纪录中不超过一个' ...

  7. 安装mysql-workbench

    sudo apt-get install mysql-workbench

  8. 《2018年云上挖矿态势分析报告》发布,非Web类应用安全风险需重点关注

    近日,阿里云安全团队发布了<2018年云上挖矿分析报告>.该报告以阿里云2018年的攻防数据为基础,对恶意挖矿态势进行了分析,并为个人和企业提出了合理的安全防护建议. 报告指出,尽管加密货 ...

  9. alert对象相关问题

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. [转]js的键盘事件

    类型 键盘事件用来描述键盘行为,主要有keydown.keypress.keyup三个事件 keydown 当用户按下键盘上的任意键时触发,如果按住不放的话,会重复触发该事件 <div id=& ...