Beijing Guards

如何用Python爬取中国土地市场网2000-2023年土地出让数据(含经纬度) 本文详细介绍了如何使用Python爬取中国土地市场网2000-2023年的土地出让数据(含经纬度),提供了一套高效的技术方案。通过应对动态加载的反爬机制、优化地理编码数据存储和设计异常处理流程,帮助开发者建立自动化数据采集管道。方案已在商业地产分析项目中验证,可稳定采集超过50万条土地交易记录。 阅读详情

题目描述

Beijing was once surrounded by four rings of city walls: the Forbidden City Wall, the Imperial City Wall, the Inner City Wall, and finally the Outer City Wall. Most of these walls were demolished in the 50s and 60s to make way for roads. The walls were protected by guard towers, and there was a guard living in each tower. The wall can be considered to be a large ring, where every guard tower has exaetly two neighbors.

The guard had to keep an eye on his section of the wall all day, so he had to stay in the tower. This is a very boring job, thus it is important to keep the guards motivated. The best way to motivate a guard is to give him lots of awards. There are several different types of awards that can be given: the Distinguished Service Award, the Nicest Uniform Award, the Master Guard Award, the Superior Eyesight Award, etc. The Central Department of City Guards determined how many awards have to be given to each of the guards. An award can be given to more than one guard. However, you have to pay attention to one thing: you should not give the same award to two neighbors, since a guard cannot be proud of his award if his neighbor already has this award. The task is to write a program that determines how many different types of awards are required to keep all the guards motivated.

输入

The input contains several blocks of test eases. Each case begins with a line containing a single integer ln100000, the number of guard towers. The next n lines correspond to the n guards: each line contains an integer, the number of awards the guard requires. Each guard requires at least 1, and at most l00000 awards. Guard i and i + 1 are neighbors, they cannot receive the same award. The first guard and the last guard are also neighbors.

The input is terminated by a block with n = 0.

输出

For each test case, you have to output a line containing a single integer, the minimum number x of award types that allows us to motivate the guards. That is, if we have x types of awards, then we can give as many awards to each guard as he requires, and we can do it in such a way that the same type of award is not given to neighboring guards. A guard can receive only one award from each type.

样例输入:

3
4
2
2
5
2
2
2
2
2
5
1
1
1
1
1
0

样例输出:

8
5
3

写这道题的过程真是一言难尽,一直提交一直wrong。。。。。。
后来边输入边判断就过了。。。。。。

上代码:

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
const int inf = 0x3f3f3f3f;
using namespace std;
int n;
const int MAX = 2e5 + 5;
int a[MAX];
int l[MAX],r[MAX];
bool solve(int what)
{
	long long left=a[1];
	long long right=what-a[1];
	l[1]=a[1];
	r[1]=0;
	for(int i=2;i<=n;i++)
	{
		if(i%2==1)
		{
//			r[i]=min(right-r[i-1],a[i]);
			if(right-r[i-1]<a[i])r[i]=right-r[i-1];
			else r[i]=a[i];
			l[i]=a[i]-r[i];
		}
		else
		{
//			l[i]=min(left-l[i-1],a[i]);
			if(left-l[i-1]<a[i])l[i]=left-l[i-1];
			else l[i]=a[i];
			r[i]=a[i]-l[i];
		}
	}
	return l[n]==0;
}
int  main()
{
	while(1)
	{
		scanf("%d",&n);
		if(n==0)
		{
			break;
		}
		int i,j;
		int maxx = 0;
		for(int i = 1; i<=n; i++) {
			scanf("%d",&a[i]);
			maxx = max(maxx,a[i]+a[i-1]);
		}
		maxx = max(maxx,a[1]+a[n]);
		if(n%2==0)
		{
			printf("%d\n",maxx);
		}
		else
		{
			if(n==1)
			{
				printf("%d\n",a[1]);
			}
			else
			{
				int lb=maxx,ub=inf,mid;
				while(lb < ub) {
				mid = (lb+ub)>>1;
				if(solve(mid)) ub = mid;
				else lb = mid+1;
				}
				printf("%d\n",lb);
			}
		}
	}
	return 0;
}


一道二分+贪心的题目,在输入为偶数是较为容易判断,为奇数时,就比较难想到了
以第一个所需要的数目来解析,
如果一组数1 2 3 4 5 6 7 8 9
第一个需要的个数为3
那么就以1 2 3 这三个数为左方,其余为右方,判断到最后一个,是否在没有使用左方数字的情况下,完成奖励分配即可
使用二分,找到那个最小的值

AntV G6避坑指南:折叠树状图那些意想不到的BUG(附解决方案) 本文深入剖析了在React项目中使用AntV G6实现折叠树状图时,从图标错乱、数据同步到状态管理的常见BUG与解决方案。文章基于实战经验,详细解读了G6的内部机制,提供了从环境配置、自定义节点绘制到事件处理与性能优化的完整避坑指南,帮助开发者彻底解决折叠展开功能的疑难杂症。 阅读详情

相关推荐

浅谈MOS管的发热原因和解决办法

解读一下开关管发热原因,解决方案和开关损耗测试。

qq_45508321的博客 1万+

UVA 1335 - Beijing Guards

Beijing was once surrounded by four rings of city walls: the Forbidden City Wall, the Imperial City Wall, the Inner City Wall, and finally the Outer City Wall. Most of these walls were demolished in t...

why932346109的博客 225

【从零开始玩量化7】easyTrader: 自动化(程序化)交易利器

前面的文章,我们介绍了数据获取工具AKShare, 量化回测工具backtrader等,这一篇,介绍程序化交易工具easyTrader。作者网名食灯鬼,目前项目在Github上的star数已经有6.7k。这可能是目前,开源能找到的,最好用的程序化交易库了。本文介绍了easyTrader的简单用法,这个包还有很多功能,后续再继续写文章探究。

量化投资助手的博客 1万+

长城守卫(Beijing Guards,CERC 2004,LA3177)

长城守卫,分治法

Leo的博客 2334

腾讯混元3D世界模型2.0实战:从AI生成到Unity/UE引擎集成全指南

生成式AI正在重塑3D内容创作流程,其核心原理是通过大语言模型理解自然语言描述,并驱动多阶段生成流水线自动创建3D资产与场景。这项技术为游戏开发、虚拟仿真和数字孪生领域带来了革命性的效率提升,能够将传统需要数周的美术协作流程压缩至几分钟。在实际应用中,开发者需要掌握本地环境部署、模型推理优化以及生成资产与主流游戏引擎的集成工作流。本文以腾讯开源的混元3D世界模型为例,详细解析如何将AI生成的场景通过插件高效导入Unity和Unreal Engine,并针对光照烘焙、材质调整、性能优化等工程实践问题提供解决方

cnracht8153的博客 1396

YOLOv8_obb的C++工程部署实战:从模型转换到实时视频推理

本文详细介绍了YOLOv8_obb模型在C++环境下的完整工程部署流程,涵盖从PyTorch模型到ONNX格式的转换、基于ONNX Runtime的C++推理引擎搭建、旋转框后处理解析,以及实时视频流处理与性能优化。文章重点解析了模型转换的关键参数、环境配置的常见问题、核心推理代码的实现,并提供了实用的避坑指南,旨在帮助开发者高效完成YOLOv8_obb的C++工程部署。

weixin_29100927的博客 46

uva 1335 Beijing Guards(二分)

uva 1335 Beijing Guards Beijing was once surrounded by four rings of city walls: the Forbidden City Wall, the Imperial City Wall, the Inner City Wall, and finally the Outer City Wall. Most of t

总有那么一群人喜欢盯着我的博客看,估计这是他们见过最长的博客名,我必须得告诉他们博客名最长可以写多长 772

Python+OpenCV实战:雨天车牌识别准确率提升300%的5个关键技巧

本文针对雨天车牌识别准确率骤降的难题,分享了五个基于Python和OpenCV的实战技巧。通过暗通道先验去雾、雨纹抑制、光照不变量颜色空间转换、多尺度自适应阈值分割以及融合传统特征与轻量级深度学习的混合识别策略,系统性地提升了算法在恶劣天气下的鲁棒性。这些方法能有效解决图像模糊、对比度低、字符断裂粘连等问题,为智能交通等实际应用提供可靠解决方案。

k8l9m0n的博客 717

AYITACM2016省赛第三周M - Beijing Guards(贪心+二分)

Beijing was once surrounded by four rings of city walls: the Forbidden City Wall, the Imperial City Wall, the Inner City Wall, and finally the Outer City Wall. Most of these walls were demolished in

linyuxilu的博客 789

手把手教你学PCIE--所有 PF(Physical Function)共同管理和分配 VF

但具体如何分配和使用 VF 取决于硬件设计、驱动程序配置以及实际应用场景。

MHD0815的博客 1463

vue3 - 高德地图定位出错Get ipLocation failed.Geolocation permission denied.(info: “FAILED“ | status: 0)报错解决!

vue3,nuxt3,高德地图,定位,位置,报错,AMap.Geolocation,解决报当前定位失败,高德地图H5 定位失败报错,web网页网站,报错详细解决教程,Get ipLocation failed.Geolocation permission denied.,高德地图定位报错info: "FAILED",高德地图status: 0,已经是https了还是报错,确保了浏览器位置已经开了,手机定位也开了,没解决,H5页面在ios的浏览器上使用 高德地图 报当前定位失败Geolocation,移动端设

✅ 精选推荐文章 6771

UVa 1335 Beijing Guards

摘要 题目考察环形相邻约束下的资源分配问题。给定n个环形排列的守卫,每个守卫需要一定数量的奖项,且相邻守卫不能获得相同奖项。要求确定满足条件的最小奖项类型数x。关键思路是:当n为偶数时,x取相邻需求和的最大值;当n为奇数时,采用二分法结合贪心策略验证可行性。贪心验证通过交替分配两类奖项池(相同/不同)来确保约束条件,时间复杂度为O(n log maxAnswer)。最终解答需处理环形特例,如单独守卫或偶数情况直接求解,奇数情况则通过二分优化。

寂静山林 939

SAP 物料主数据 Forecasting 视图,别把预测只当成一个数字字段

摘要(150字): SAP S/4HANA物料主数据的Forecasting视图常被忽视,但对依赖历史消耗规律的物料至关重要。该功能基于工厂维度的历史消耗数据,结合预测参数自动计算未来需求,动态调整重订货点和安全库存。预测模板(Forecast Profile)能标准化参数设置,而消耗数据(Consumption Values)的质量直接影响预测结果。预测值作为MRP输入,需注意保存操作才能生效。自动重订货点功能通过分析消耗波动和服务水平,实现库存策略的动态优化。Individual Forecast功能则

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1436

UVA 1335 Beijing Guards

题目: M - Beijing Guards Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UVA 1335 Description Beijing was once surrounded by four rings of city walls: 

894383755的博客 620

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

uva 1335 Beijing Guards

巧妙之处在于当人数是奇数时,其选择方案是第一个人尽量靠左选,以后编号为偶数的人尽量靠左选,编号为奇数的人尽量靠右选。 然后二分枚举可能的礼物数量,看最后是否满足题目要求——第一个人和最后一个人不选重。 细节问题总结:重定义全局变量会导致错误,切不好检查出来,应谨慎。 #include #include #include using namespace std; const int maxn

GejinZ 906

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

UVA 1335 Beijing Guards

1335 - Beijing Guards Time limit: 3.000 seconds

Houheshuai的专栏 801

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

UVALIVE 3177 Beijing Guards

传送门:UVALIVE 3177 #include #include #include #include #include using namespace std; const int maxn = 100000; int a[maxn],b[maxn],c[maxn]; int n; int solve(int p) { int x = a[0],y = p-a[0]; b[

论菜鸟的自我修养。。。 410

[UVa 1335]Beijing Guards

题解 拿到题,没什么头绪,我们模拟一下,很容易得出一个结论: 如果$n$为偶数,那么答案就是$max(r[i]+r[i+1])$。具体方案就是,如果$i$为奇数,那么取$[1,r[i]]$;若$i$为偶数,则取$[ans-r[i]+1,ans]$。 同样我们此时的$ans$是答案的下界。 可当$n$为奇数时,我们这样贪心策略出现问题就是由于$1$和$n$都是奇数,会取$[1,r[1]]...

weixin_30385925的博客 141

UVALIVE 3177 Beijing Guards

Description Beijing was once surrounded by four rings of city walls: the Forbidden City Wall, the Imperial City Wall, the Inner City Wall, and finally the Outer City Wall. Most of these w...

aims714563740的博客 159

uva1335 Beijing Guards

二分答案+贪心

YHaX的博客 316

uva 1335 - Beijing Guards

题目链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=456&page=show_problem&problem=4081 好题!不得不说贪心真的很强大和千变万化。。。 1.  二分答案p,编号为偶数的尽量往前取,编号为奇数个的尽量往后取。 2.  第一个取第1~r

D_Double's Journey 1446

UVA1335 Beijing Guards 贪心

训练指南上一道贪心,很经典 Beijing Guards Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu [Submit]   [Go Back]   [Status]   Description Beij

694

【Beijing Guards】【UVA - 1335】(思维)

题目:     Beijing was once surrounded by four rings of city walls: the Forbidden City Wall, the Imperial City Wall, the Inner City Wall, and finally the Outer City Wall. Most of these walls were demoli...

哇哈哈哈的博客 246

【UVA1335】Beijing Guards

题面   Beijing was once surrounded by four rings of city walls: the Forbidden City Wall, the Imperial City Wall, the Inner City Wall, and finally the Outer City Wall. Most of these walls were demolishe

清疚的博客 354

LA 3177 Beijing Guards

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1178 如果n是偶数,很显然最少需要最大的两个相邻士兵的要求礼物和. 如果n是奇数,那就要二分答案了,对于p个礼物,第1个人需要r[1]个礼物,记为左边的礼物,剩下的p-r[1]个礼物记为

蚂蚁大战大象 853
上一篇: 二分应用
下一篇: 组装电脑
大橘为重eleven
博客等级 码龄8年 35粉丝 103原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值