`
rex686568
  • 浏览: 9054 次
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

长城守卫 Beijing guards CERC 2004 LA3177 解题总结

 
阅读更多

在最小值,最大值的问题 或者没有办法确定答案时候, 可以使用二分答案法.

#include <cstdio>
#include <iostream>
#include <fstream>
using namespace std;

int main(){
	fstream f("E:\\text.txt");

	int n;
	int gift[100];
	bool used[100];
	memset(used, 0, sizeof(used));
	int ans = 0;
	f >> n;
	for (int i = 0; i < n; i++){
		f >> gift[i];
	}
	ans = gift[0];
	for (int i = 0; i < gift[0]; i++) used[i] = true;
	
	for (int i = 1; i < n; i++){

		int g = gift[i];
		int j = 0;
		while (1){
			if (used[j]) used[j] = false;
			else {
				g--; used[j] = true;
				if (g == 0) break;
			}
			if (j+1>ans) ans = j+1;
			j++;
		}
	}
	int last=0;
	for (int i = gift[0]; i < ans; i++){
		if (!used[i]) last++;
	}
	for (int i = 0; i < gift[0]; i++){
		if (used[i]){
			if (last>0)
				last--;
			else
			 ans++;
		}
	}
	cout << ans;
}


分享到:
评论

相关推荐

    vue2.0 实现导航守卫(路由守卫)

    对此,vue-route 提供的 beforeRouteUpdate 可以方便地实现导航守卫(navigation-guards)。 导航守卫(navigation-guards)这个名字,听起来怪怪的,但既然官方文档是这样翻译的,就姑且这么叫吧。 贴上文档地址:...

    vue2.0 实现导航守卫的具体用法(路由守卫)

    对此,vue-route 提供的 beforeRouteUpdate 可以方便地实现导航守卫(navigation-guards)。 导航守卫(navigation-guards)这个名字,听起来怪怪的,但既然官方文档是这样翻译的,就姑且这么叫吧。 贴上文档地址:...

    WPF.DazzleUI.zip_Guards! Guards!_WPF_triangleai1

    WPF Imitation 360 Guards 9.0 Interface Design

    vue-router 实现导航守卫(路由卫士)的实例代码

    对此,vue-route 提供的 beforeRouteUpdate 可以方便地实现导航守卫(navigation-guards)。 导航守卫(navigation-guards)这个名字,听起来怪怪的,但既然官方文档是这样翻译的,就姑且这么叫吧。 贴上文档地址:...

    前端项目-guards.zip

    前端项目-guards,使用类(或任何其他选择器)保护窗体。

    详解vue-router导航守卫

    对此,vue-router 提供的 beforeEach可以方便地实现全局导航守卫(navigation-guards)。组件内部的导航守卫函数使用相同,只是函数名称不同(beforeRouteEnter 、beforeRouteUpdate(2.2 新增) 、beforeRouteLeave)...

    guards:为方法参数和返回值提供运行时检查

    您也可以添加自己的守卫。 您的代码将受到它们的保护,javac 和 IDEA 插件会尽可能多地收集它们并在编码过程中为您提供帮助。 请注意,有许多过时的旧 JavaDoc。 一些基本概念已经改变。 具体来说,最初的概念

    详解vue beforeEach 死循环问题解决方法

    导航守卫(navigation-guards)这个名字,听起来怪怪的,但既然官方文档是这样翻译的,就姑且这么叫吧。** 文档地址:https://router.vuejs.org/zh/guide/advanced/navigation-guards.html 举个例子,当

    broccoli-es7-decorator-jshint-guards

    西兰花-es7-decorator-jshint-guards 将您的ES7装饰器包装在jshint防护中,以使jshint不会抱怨它(尚未)理解的新语法。安装从NPM: npm install broccoli-es7-decorator-jshint-guards --save-dev西兰花过滤器假设...

    here-maps-type-guards:这里的Map的TypeScript类型定义的受保护版本

    可以使用以下命令进行安装: npm install here-maps-type-guards 为了使用here-maps-type-guards,不需要在tsconfig文件中包括任何外部类型定义文件。守卫该模块为HERE Maps中可用的每个模块提供了防护。 防护对于...

    Search Guards-crx插件

    ****单击“添加到Chrome”,即表示我接受并同意安装Search-Guards Chrome扩展并将Chrome:trade_mark:默认搜索设置为该服务以及《使用条款和隐私权政策》所提供的默认搜索。条款和隐私:https://search-guards.com ...

    type-guards:简单的实用程序,用于运行时类型检查,如果与TypeScript一起使用,还可以分配正确的类型

    type-guards 该模块允许您以强类型明确方式编写运行时验证。 换句话说,它为您提供了一种不错的方法,即通过编写验证函数并使代码保持DRY并随其获取TypeScript类型。安装 $ yarn add type-guards例子 import * as tg...

    apollo-type-guards:二进制文件,可用于为Apollo生成的类型添加保护功能

    安装使用npm: npm install --save-dev apollo-type-guards 含纱线: yarn add --dev apollo-type-guards用法运行apollo client:codegen CLI以从架构中生成类型文件跑apollo-type-guards --globDir="glob/to/...

    Minimization of the maximum distance between the two guards patrolling a polygonal region

    The two-guard problem asks whether two guards can walk to detect an unpredictable, moving target in a polygonal region P. no matter how fast the target moves, and if so, construct a walk schedule of ...

    angular-router-fast-and-guards

    通过使用命令工具执行命令ng new router-fast-and-guards来为应用程序创建工作区 ? 您是否要在工作空间中执行更严格的类型检查和更严格的捆绑包预算? 此设置有助于提高可维护性并提前发现错误。 有关更多信息,请...

    pattern-guard:JavaScript模式卫士:guard:

    用法const guards = require ( 'pattern-guard' )const [ a , b , c ] = [ 1 , 3 , 7 ]const result = guards ( { a , b , c } ) ` | a &gt; b = 1337 | b &gt; c = 999 | c &gt; a = 42 | c &gt; b = 11`console . log ( result...

Global site tag (gtag.js) - Google Analytics