首页 > 其他分享 >CF1872B The Corridor or There and Back Again

CF1872B The Corridor or There and Back Again

时间:2023-10-15 17:15:17浏览次数:39  
标签:Again CF1872B int There Back Corridor

CF1872B The Corridor or There and Back Again

观察第二组样例的解释,注意这句话:“第二个陷阱限制了你”。这启发我们计算经过每个陷阱之后最多还能向前走到哪里,然后取 \(\min\) 得到答案。

现在的问题是如何求出每个陷阱限制的最远可到达点。

由于要求折返,因此对于第 \(i\) 个陷阱,它限制的最远可到达点为 \(d_i+\lfloor\dfrac{s_i}{2}\rfloor\)。同时注意到要求“返回时间严格小于 \(s_i\)”,所以对于偶数,直接除以 \(2\) 并向下取整是不行的,要先让 \(s_i\) 自减 \(1\)。

时间复杂度 \(\mathcal{O}(n)\)。

代码:

#include<bits/stdc++.h>
using namespace std;
bool Mbegin;
void File_Work(){
	freopen("test.in","r",stdin);
	freopen("test.out","w",stdout);
}
namespace Fast_In_Out{
	char buf[1<<21],*P1=buf,*P2=buf;
	#define gc (P1==P2&&(P2=(P1=buf)+fread(buf,1,1<<21,stdin),P1==P2)?EOF:*P1++)
	int read(){
		int f=1,x=0;
		char c=gc;
		while(c<'0'||c>'9'){
			if(c=='-')
			    f=-1;
			c=gc;
		}
		while(c>='0'&&c<='9'){
			x=x*10+c-'0';
			c=gc;
		}
		return f*x;
	}
	void write(int x){
		if(x<0)
			x=-x,putchar('-');
		if(x>9)
			write(x/10);
		putchar(x%10+'0');
	}
	#undef gc
}
using namespace Fast_In_Out;
const int N=108,oo=1e9+8;
int n,a[N];
void solve(){
	n=read();
	int ans=oo;
	for(int i=1;i<=n;i++){
		int d=read(),s=read();
		if(s%2==0)
			s--;
		ans=min(ans,d+s/2);
	}
	write(ans),putchar('\n'); 
}
bool Mend;
int main(){
	fprintf(stderr,"%.3lf MB\n\n\n",(&Mbegin-&Mend)/1048576.0);
	int testnum=read();
	while(testnum--)
		solve();	
	fprintf(stderr,"\n\n\n%.0lf ms",1e3*clock()/CLOCKS_PER_SEC);
	return 0;
}

标签:Again,CF1872B,int,There,Back,Corridor
From: https://www.cnblogs.com/NatoriBlog/p/17765811.html

相关文章

  • The build restored NuGet packages. Build the project again to include these pack
    ThebuildrestoredNuGetpackages.Buildtheprojectagaintoincludethesepackagesinthebuild 在VisualStudio2022中构建代码时出现此错误。严重性代码说明项目文件行禁止显示状态错误ThebuildrestoredNuGetpackages.Buildtheprojectagainto......
  • 【线段树合并】CF1805E There Should Be a Lot of Maximums 题解
    CF1805E待补:有另解看到维护树上问题,可以想到线段树合并。但直接维护显然不行,要一点技巧。发现\(val\)的出现次数\(cnt_{val}\)如果\(\ge3\),那么一定是一个候选项,若\(cnt_{val}=1\),那么一定不能作为候选项。于是可以用权值线段树维护对于\(val\)有\(cnt_{val}=......
  • go-ethereum mint nft用户支付实现
    代码:packagemain//签名用的公钥私钥也是采用的owner的公钥私钥import( "context" "fmt" "math/big" "user-pay/triplec" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil&qu......
  • go-ethereum设置signer
    设置代码:packagemain//签名用的公钥私钥也是采用的owner的公钥私钥import( "fmt" "set_signer/triplec" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethc......
  • Virtual memory running out when there are free physical memory?
    Virtualmemoryrunningoutwhentherearefreephysicalmemory?AskQuestionAsked 7years,8monthsagoModified 7years,8monthsagoViewed 1ktimes  1Myfirefoxsuddenlybecomesluggishandthenfroze.IopenedProcessExplore......
  • E---句子中的there 与 here
    译文:CallstodisassemblealltelescopesonMaunaKeaortobanfuturedevelopmentthere ignoretherealitythatastronomyandHawaiianculturebothseektoanswerbigquestionsaboutwhoweare,wherewecomefromandwherewearegoing.翻译:拆除莫纳克亚......
  • [IJCAI 2023]Fighting against Organized Fraudsters Using Risk Diffusion-based Par
    [IJCAI2023]FightingagainstOrganizedFraudstersUsingRiskDiffusion-basedParallelGraphNeuralNetwork文章设计了一种基于社区的医疗保险欺诈行为检测。模型为了提高精度,模型设计了一组异构图模型和一组同构图模型。输入的异构图是保险受益人-医疗服务提供者的图,......
  • yarn 出现 【 info There appears to be trouble with your network connection. Retr
    第一种解决方案#调整为taobao镜像源yarnconfigsetregistryhttps://registry.npm.taobao.org我用了没用,可以试试第二种解决方案要在项目根目录下创建后缀名为.yarnrc的文件,并设置network-timeout的值为600000,你可以按照以下步骤进行操作:打开文本编辑器,例如Note......
  • Redis - 出现ERROR:WRONGTYPE Operation against a key holding the wrong kind of val
    原因:用的方法与redis服务器中存储数据的类型存在冲突。比如:有一个key的数据存储的是list类型的,但使用redis执行数据操作的时候却使用了非list的操作方法。 对一个Redis键执行不兼容的操作,这个错误通常发生在以下情况:1、类型不匹配:试图执行的操作与键存储的数据类型不匹配。例......
  • could only be written to 0 of the 1 minReplication nodes. There are 1 datanode(s
    flume往HDFS写入数据报错如下所示:couldonlybewrittento0ofthe1minReplicationnodes.Thereare1datanode(s)runningand1node错误原因是:没有可用的datanode了,hdfs空间满了错误解决方法是:HDFS磁盘扩容清理HDFS上冗余文件......