首页 > 其他分享 >B. Ideal Point

B. Ideal Point

时间:2023-03-13 12:22:22浏览次数:42  
标签:const Point int 线段 cin -- Ideal include

B. Ideal Point

image

思路

  1. 首先删除不包含点k的线段,因为这些线段对使\(f(k) > f(x)\)没有贡献
  2. 然后再考虑剩余的线段中覆盖得到的f(x)最大值是否唯一(由于前面的处理,所有线段均包含点k,如果最大值唯一的话,那么只能是k点),如果最大值不唯一的话就无论如何删除线段也无法满足要求(由于所有线段均包含点k,如果想要让其他最大值减小的话,f(x)也会随之减小,因此此时删边没有任何意义)

代码1差分与前缀和

点击查看代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<cctype>
using namespace std;

#define X first
#define Y second

typedef pair<int,int> pii;
typedef long long LL;
const char nl = '\n';
const int N = 1e6+10;
const int M = 2e5+10;
int d[55];
void solve(){
	int t;
	cin >> t;
	while(t -- ){
		memset(d,0,sizeof d);
		int n,k;
		cin >> n >> k;
		while(n --){
			int l,r;
			cin >> l >> r;
			if(l > k || r < k)continue;
			d[l] ++;
			d[r + 1] --;
		}
		int maxn = 0,maxp = 0;
		for(int i = 1; i <= 50; i ++ ){
			d[i] += d[i - 1];
			if(d[i] > maxn){
				maxn = d[i];
				maxp = i;
			}
		}
		if(maxp == k && d[k - 1] != d[k] && d[k + 1] != d[k])cout << "yes" << nl;
		else cout << "no" << nl;
	}
	
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);

	solve();
}

代码2

可以维护所有线段的公共区间快速判断,如果最后所有线段的公共区间长度为1则yes,否则no

点击查看代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<cctype>
using namespace std;

#define X first
#define Y second

typedef pair<int,int> pii;
typedef long long LL;
const char nl = '\n';
const int N = 1e6+10;
const int M = 2e5+10;
void solve(){
	int t;
	cin >> t;
	while(t -- ){
		int n,k;
		cin >> n >> k;
		int L = 0,R = 114514;
		while(n --){
			int l,r;
			cin >> l >> r;
			if(l > k || r < k)continue;
			L = max(L,l);
			R = min(R,r);
		}
		if(L == R)cout << "yes" << nl;
		else cout << "no" << nl;
	}
	
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);

	solve();
}

标签:const,Point,int,线段,cin,--,Ideal,include
From: https://www.cnblogs.com/J-12045/p/17210908.html

相关文章

  • 伞源科技Pinpoint和sonarQube对比
    伞源科技Pinpoint和sonarQube对比测试背景使用工具:源伞科技PinpointSonarqube测试项目:本地测试框架项目两个文件文件1:AsyncHttpClientUtil.java文件2:FileUtil.java测试结......
  • IPM逆透视变换问题1/3之:Vanish Point
    IPM逆透视变换问题1/3之:VanishPoint重要提醒:首先确定坐标系朝向,简化步骤须做出说明。1.坐标系#worldcoord[x-right,y-front,z-up]#cameracoord[x-right,y......
  • AGC051E[Middle Point] 题解
    条件转化我们记:\[M=\{x|x=\frac{a}{2^b},a,b\in\mathbb{Z}\}\\M^*=\{x|x\inM,x\ge0\}\]令下文向量均为二维向量,记给定点集为\({\vec{p_n}}\)那么原题即为求满足\(......
  • 运行servlet项目时Failed to initialize end point associated with ProtocolHandler
    应该是端口被占用了,https://blog.csdn.net/qq_23853743/article/details/84432365这个是找到对应的pid然后杀死占用端口的进程。还有一招是书命令,没试过https://blog.c......
  • 【copy from】IEEE-754 Floating Point Converter
    图片截取自:IEEE-754FloatingPointConverter传送门:https://www.h-schmidt.net/FloatConverter/IEEE754.htmlExponent:用移码表示(格式与补码类似,只是MSB用1表示正数,用......
  • 转:web自动化-----------报错 Element * is not clickable at point,Other element woul
    出现报错Otherelementwouldreceivetheclick:的原因是;当你selenium中click()点击事件时,所选中的标签被外部div吸收了,因此解决办法就是进入里面进行点击操作。drive......
  • Static Probe Points in GDB
    参考:https://sourceware.org/gdb/onlinedocs/gdb/Static-Probe-Points.htmlhttps://man7.org/linux/man-pages/man3/stapprobes.3stap.html infoprobes--Showav......
  • What is Point ?
    学习心态指针其实跟一些运算符的表达式类似(例如i++,i--),它通过符号隐藏了内部的计算过程,只要学习者逐步的分解开,就很容易理解了。学习指针的时候,尽量想象底层硬件的工作方......
  • model checkpoint
    Amodelcheckpointisasavedcopyofthetrainedweightsandbiasesofaneuralnetworkmodelataspecificpointintimeduringthetrainingprocess.Itcan......
  • SharePoint Online 修改管理员角色不生效
    前言最近,公司新入职一个员工,据说是一个SharePoint大神级的人物,所以,来了先给他一个管理员角色。但是,发现了个奇怪的事情,明明给了角色,点击了确认,却一直不生效......