ZZULIOJ--2842: szg的情敌(差分)

这是一个关于如何处理一个人物在面对多个粉丝时避免‘沦陷’的算法问题。输入包含粉丝的到达和离开时间,以及能同时面对的最大粉丝数。通过对时间窗口的处理,判断在任意时刻是否存在超过最大粉丝数的情况,输出‘YES’表示沦陷,‘NO’表示没有沦陷。提供的代码实现了这一逻辑,并给出了几个测试用例。

题目描述

zyz实在是太英俊了,同时他又非常的喜欢学习,这因此吸引来了无数女粉丝。
每次在zyz去实验室的路上都会有很多女粉丝找zyz搭讪,但是zyz最多只能同时面对m个女粉丝,
如果同时面对的女粉丝数大于m,那么他就会沦陷,从而无法到达实验室学习。
现在给出n个女粉丝的到达时间和离开时间,
问zyz是否沦陷。

输入

第一行一个T (T<=10) 表示输入实例个数,接着有T个样例。
每个样例第一行输入两个整数n和m,分别表示女粉丝的个数和zyz最多能同时面对的粉丝的个数。(0<=n<=200,0<=m<=300)
接下来n行每行输入两个整数x和y,分别表示该女粉丝的到达时间和离开时间。(0<=x<=y<=1e5)

输出

对于每个样例,如果zyz沦陷,请输出"YES",否则输出"NO";

样例输入 Copy

5
2 1
1 2
2 3
4 4
1 8
2 7
3 6
4 5
4 3
1 8
2 7
3 6
4 5
5 4
1 10
2 9
3 8
4 7
5 6
3 2
1 1
1 2
1 3

样例输出 Copy

NO
NO
YES
YES
NO

提示

如果女粉丝的到达时间为6,离开时间也为6,说明女粉丝见到zyz后有些失望,那么她就会立刻离开,555...
如szg找zyz搭讪的到达时间为6,离开时间为7;另一位女粉丝到达时间为7,离开时间为8。那么在6到8这段时间算最多只有一位粉丝存在。
数据弱化了

#include<bits/stdc++.h>
using namespace std;
const int N=100010;
int a[N];
int main()
{
	int n,m;
	int T;
	cin>>T;
	while(T--)
	{
		int n,m;
		cin>>n>>m;
		int maxt=0;
		memset(a,0,sizeof(a));//1.
		for(int i=1;i<=n;i++)
		{
			int x,y;
			cin>>x>>y;
			a[x]++;
			a[y]--;
			if(y>maxt)maxt=y;
		}
		int f=0;
		int sum=0;
		
		for(int i=0;i<=maxt;i++)
		{
			sum+=a[i];
			if(sum>m)
			{
				cout<<"YES"<<endl;
				f=1;
				break;
			}
		}
		if(f==0) cout<<"NO"<<endl;
		
	}
	
	return 0;
}

 

cython安装完成后进行opencv的安装仍显示 (.venv) C:\Users\13373\Desktop\PythonProject>pip install opencv-python Collecting opencv-python Using cached opencv_python-4.12.0.88-cp37-abi3-win_amd64.whl.metadata (19 kB) Collecting numpy<2.3.0,>=2 (from opencv-python) Using cached numpy-2.2.6.tar.gz (20.3 MB) Installing build dependencies … done Getting requirements to build wheel … done Installing backend dependencies … done Preparing metadata (pyproject.toml) … error error: subprocess-exited-with-error × Preparing metadata (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [19 lines of output] + C:\Users\13373\Desktop\PythonProject.venv\Scripts\python.exe C:\Users\13373\AppData\Local\Temp\pip-install-1nnmd_68\numpy_2c804fafc9c64850a28be36285904715\vendored-meson\meson\meson.py setup C:\Users\13373\AppData\Local\Temp\pip-install-1nnmd_68\numpy_2c804fafc9c64850a28be36285904715 C:\Users\13373\AppData\Local\Temp\pip-install-1nnmd_68\numpy_2c804fafc9c64850a28be36285904715.mesonpy-5w6s6szg -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md --native-file=C:\Users\13373\AppData\Local\Temp\pip-install-1nnmd_68\numpy_2c804fafc9c64850a28be36285904715.mesonpy-5w6s6szg\meson-python-native-file.ini The Meson build system Version: 1.5.2 Source dir: C:\Users\13373\AppData\Local\Temp\pip-install-1nnmd_68\numpy_2c804fafc9c64850a28be36285904715 Build dir: C:\Users\13373\AppData\Local\Temp\pip-install-1nnmd_68\numpy_2c804fafc9c64850a28be36285904715.mesonpy-5w6s6szg Build type: native build Project name: NumPy Project version: 2.2.6 Activating VS 18.0.2 C compiler for the host machine: cl (msvc 19.50.35719 “用于 x64 的 Microsoft ® C/C++ 优化编译器 19.50.35719 版”) C linker for the host machine: link link 14.50.35719.0 C++ compiler for the host machine: cl (msvc 19.50.35719 “用于 x64 的 Microsoft ® C/C++ 优化编译器 19.50.35719 版”) C++ linker for the host machine: link link 14.50.35719.0 ..\meson.build:1:0: ERROR: Unknown compiler(s): [['cython'], ['cython3']] The following exception(s) were encountered: Running `cython3 -V` gave "[WinError 2] 系统找不到指定的文件。" A full log can be found at C:\Users\13373\AppData\Local\Temp\pip-install-1nnmd_68\numpy_2c804fafc9c64850a28be36285904715\.mesonpy-5w6s6szg\meson-logs\meson-log.txt [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. [notice] A new release of pip is available: 25.1.1 -> 25.3 [notice] To update, run: python.exe -m pip install --upgrade pip error: metadata-generation-failed × Encountered error while generating package metadata. ╰─> See above for output. note: This is an issue with the package mentioned above, not pip. hint: See above for details.
12-08
(.venv) C:\Users\13373\Desktop\PythonProject>pip install opencv-python Collecting opencv-python Using cached opencv_python-4.12.0.88-cp37-abi3-win_amd64.whl.metadata (19 kB) Collecting numpy<2.3.0,>=2 (from opencv-python) Using cached numpy-2.2.6.tar.gz (20.3 MB) Installing build dependencies ... done Getting requirements to build wheel ... done Installing backend dependencies ... done Preparing metadata (pyproject.toml) ... error error: subprocess-exited-with-error × Preparing metadata (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [19 lines of output] + C:\Users\13373\Desktop\PythonProject\.venv\Scripts\python.exe C:\Users\13373\AppData\Local\Temp\pip-install-1nnmd_68\numpy_2c804fafc9c64850a28be36285904715\vendored-meson\meson\meson.py setup C:\Users\13373\AppData\Local\Temp\pip-install-1nnmd_68\numpy_2c804fafc9c64850a28be36285904715 C:\Users\13373\AppData\Local\Temp\pip-install-1nnmd_68\numpy_2c804fafc9c64850a28be36285904715\.mesonpy-5w6s6szg -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md --native-file=C:\Users\13373\AppData\Local\Temp\pip-install-1nnmd_68\numpy_2c804fafc9c64850a28be36285904715\.mesonpy-5w6s6szg\meson-python-native-file.ini The Meson build system Version: 1.5.2 Source dir: C:\Users\13373\AppData\Local\Temp\pip-install-1nnmd_68\numpy_2c804fafc9c64850a28be36285904715 Build dir: C:\Users\13373\AppData\Local\Temp\pip-install-1nnmd_68\numpy_2c804fafc9c64850a28be36285904715\.mesonpy-5w6s6szg Build type: native build Project name: NumPy Project version: 2.2.6 Activating VS 18.0.2 C compiler for the host machine: cl (msvc 19.50.35719 "用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.50.35719 版") C linker for the host machine: link link 14.50.35719.0 C++ compiler for the host machine: cl (msvc 19.50.35719 "用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.50.35719 版") C++ linker for the host machine: link link 14.50.35719.0 ..\meson.build:1:0: ERROR: Unknown compiler(s): [['cython'], ['cython3']] The following exception(s) were encountered: Running `cython3 -V` gave "[WinError 2] 系统找不到指定的文件。" A full log can be found at C:\Users\13373\AppData\Local\Temp\pip-install-1nnmd_68\numpy_2c804fafc9c64850a28be36285904715\.mesonpy-5w6s6szg\meson-logs\meson-log.txt [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. [notice] A new release of pip is available: 25.1.1 -> 25.3 [notice] To update, run: python.exe -m pip install --upgrade pip error: metadata-generation-failed × Encountered error while generating package metadata. ╰─> See above for output. note: This is an issue with the package mentioned above, not pip. hint: See above for details. 什么意思
12-08
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值