当前位置:网站首页>CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!) C题
CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!) C题
2022-08-02 04:25:00 【一条小小yu】
C. Virus
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
There are nn houses numbered from 11 to nn on a circle. For each 1≤i≤n−11≤i≤n−1, house ii and house i+1i+1 are neighbours; additionally, house nn and house 11 are also neighbours.
Initially, mm of these nn houses are infected by a deadly virus. Each morning, Cirno can choose a house which is uninfected and protect the house from being infected permanently.
Every day, the following things happen in order:
- Cirno chooses an uninfected house, and protect it permanently.
- All uninfected, unprotected houses which have at least one infected neighbor become infected.
Cirno wants to stop the virus from spreading. Find the minimum number of houses that will be infected in the end, if she optimally choose the houses to protect.
Note that every day Cirno always chooses a house to protect before the virus spreads. Also, a protected house will not be infected forever.
Input
The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤1041≤t≤104) — the number of test cases. Description of test cases follows.
The first line of each test case consists of two positive integers n,mn,m (5≤n≤1095≤n≤109, 1≤m≤min(n,105)1≤m≤min(n,105)) — the number of houses on the circle, and the number of houses that are initially infected.
The second line of each test case consists of mm distinct positive integers a1,a2,⋯,ama1,a2,⋯,am (1≤ai≤n1≤ai≤n) — the indices of the houses infected initially.
It is guaranteed that the sum of mm over all test cases does not exceed 105105.
Output
For each test case, output an integer on a separate line, which is the minimum number of infected houses in the end.
Example
input
Copy
8 10 3 3 6 8 6 2 2 5 20 3 3 7 12 41 5 1 11 21 31 41 10 5 2 4 6 8 10 5 5 3 2 5 4 1 1000000000 1 1 1000000000 4 1 1000000000 10 16output
Copy
7 5 11 28 9 5 2 15Note
In the first test case:
At the start of the first day, house 33, 66, 88 are infected. Choose house 22 to protect.
At the start of the second day, house 33, 44, 55, 66, 77, 88, 99 are infected. Choose house 1010 to protect.
At the start of the third day, no more houses are infected.
In the second test case:
At the start of the first day, house 22, 55 are infected. Choose house 11 to protect.
At the start of the second day, house 22, 33, 44, 55, 66 are infected. No more available houses can be protected.
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int t, n, m;
int a[N], res[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> t;
while(t --)
{
cin >> n >> m;
for(int i = 1; i <= m; i ++)cin >> a[i];
sort(a + 1, a + 1 + m);
for(int i = 1; i < m; i ++)
{
res[i] = a[i + 1] - a[i] - 1;
}
res[m] = n - (a[m] - a[1]) - 1;
sort(res + 1, res + m + 1,greater<int>());
int k = 0, cnt = 0;
for(int i = 1; i <= m; i ++)
{
//cout << cnt << '\n';
if(res[i] - 2 * k > 0)
{
if(res[i] - 2 * k == 1)cnt ++;
else cnt += res[i] - 2 * k - 1;
}
k += 2;
}
cout << n - cnt << '\n';
}
return 0;
}
边栏推荐
- Sentinel熔断之非控制台方式总结
- 列表总结
- A practice arrangement about map GIS (below) GIS practice of Redis
- Minecraft 1.18.1, 1.18.2 module development 23.3D animation armor production
- Excel如何解密工作表保护
- 深度剖析-class的几个对象(utlis,component)-瀑布流-懒加载(概念,作用,原理,实现步骤)
- 力扣练习——45 二叉树的锯齿形层次遍历
- 爬虫_爬取wasde月度供需平衡表(实例)
- 数学建模学习(76):多目标线性规划模型(理想法、线性加权法、最大最小法),模型敏感性分析
- 热爱和责任
猜你喜欢
Learn about the sequential storage structure of binary tree - heap
Minecraft 1.18.1, 1.18.2 module development 23.3D animation armor production
[Win11] PowerShell cannot activate Conda virtual environment
PyQt5_pyqtgraph mouse draws straight lines on line charts
深度剖析-class的几个对象(utlis,component)-瀑布流-懒加载(概念,作用,原理,实现步骤)
LeetCode 23: 合并K个升序链表
8月1日“海豹数藏”将全网首发民族英雄林则徐《四行行书》数字藏品!
“数字化重构系统,搞定 CEO 是第一步”
Qt编写物联网管理平台49-设备模拟工具
Minecraft 1.18.1、1.18.2模组开发 23.3D动画盔甲制作
随机推荐
ADSP21489数据手册表摘要
七月阅读:《刘慈欣科幻短篇小说集Ⅰ》笔记
自定义一个下划线分词器
P1192 台阶问题
多主复制的适用场景(1)-多IDC
批量--09---批量读文件入表
多主复制下处理写冲突(4)-多主复制拓扑
【FreeRTOS】12 任务通知——更省资源的同步方式
lvm扩容(实战无废话)
【Interview】Recruitment requirements
高等数学(第七版)同济大学 总习题三(前10题) 个人解答
Sentinel熔断之非控制台方式总结
关于地图GIS开发事项的一次实践整理(上)
How to decrypt worksheet protection in Excel
MapFi paper structure organization
Jetson Nano 2GB Developer Kit Installation Instructions
Learn about the sequential storage structure of binary tree - heap
ROS visualization of 3D target detection
LeetCode 23: 合并K个升序链表
Qt FAQ