ural 2064. Caterpillars
2064. Caterpillars
Memory limit: 64 MB
Input
Output
Sample
input | output |
---|---|
4 |
1 |
Problem Source: Ural Regional School Programming Contest 2015
/**
Create By yzx - stupidboy
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef double DB;
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define mk make_pair inline int getInt()
{
int ret = ;
char ch = ' ';
bool flag = ;
while(!(ch >= '' && ch <= ''))
{
if(ch == '-') flag ^= ;
ch = getchar();
}
while(ch >= '' && ch <= '')
{
ret = ret * + ch - '';
ch = getchar();
}
return flag ? -ret : ret;
} const int N = ;
int n, m, cnt[N];
int ans[N]; inline void input()
{
for(cin >> n; n--; )
{
int x, t;
cin >> x;
for(t = x; t < N; t += * x)
cnt[t] = max(cnt[t], x);
cnt[N - ] = max(cnt[N - ], x - (t - (N - )));
}
cin >> m;
} inline void solve()
{
for(int i = , now = -INF; i < N; i++)
{
now = max(now, cnt[i] + i);
ans[i] = max(ans[i], now - i);
}
for(int i = N - , now = -INF; i > ; i--)
{
now = max(now, cnt[i] - i);
ans[i] = max(ans[i], now + i);
} while(m--)
{
int x;
cin >> x;
cout << ans[x] << "\n";
}
} int main()
{
ios::sync_with_stdio();
input();
solve();
return ;
}
ural 2064. Caterpillars的更多相关文章
- Ural 2064:Caterpillars(思维暴力)
http://acm.timus.ru/problem.aspx?space=1&num=2064 题意:有n只虫子在爬树,每个虫子往上爬ti距离后会往下掉落ti距离,每爬一个单位距离耗费一个 ...
- 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome
题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...
- ural 2071. Juice Cocktails
2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...
- ural 2073. Log Files
2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...
- ural 2070. Interesting Numbers
2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...
- ural 2069. Hard Rock
2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...
- ural 2068. Game of Nuts
2068. Game of Nuts Time limit: 1.0 secondMemory limit: 64 MB The war for Westeros is still in proces ...
- ural 2067. Friends and Berries
2067. Friends and Berries Time limit: 2.0 secondMemory limit: 64 MB There is a group of n children. ...
- ural 2066. Simple Expression
2066. Simple Expression Time limit: 1.0 secondMemory limit: 64 MB You probably know that Alex is a v ...
随机推荐
- Linux(Ubuntu)之设定开机自启动
分两种:对自建脚本,对已安装服务 对已安装服务, 只需在/etc/rc.local中添加相应的启动命令,如: 重启后,即可自启动服务. 对自建脚本自启动: 创建脚本test,修改其权限为755,如: ...
- 设计模式之构建者模式(Builder):初步理解
构建者(Builder)设计模式(又叫生成器设计模式): 当一个类的内部数据过于复杂的时候(通常是负责持有数据的类,比如Config.VO.PO.Entity...),要创建的话可能就需要了解这个类的 ...
- Android 反编译 -- apktool、dex2jar、jd-gui
原文:http://blog.csdn.net/vipzjyno1/article/details/21039349/ apktool 最新官网: http://ibotpeaches.github. ...
- Linux下pipe使用注意事项
转自:http://blog.yufeng.info/archives/1485 Linux下的pipe使用非常广泛, shell本身就大量用pipe来粘合生产者和消费者的. 我们的服务器程序通常会用 ...
- Bootstrap简介
接下来的一段时间,想研究一下现有的网页框架,第一个不容错过的就是Bootstrap,Bootstrap 是一个用于快速开发 Web 应用程序和网站的前端框架.Bootstrap 是基于 HTML.CS ...
- 算法系列:XXX
转载自http://www.cnblogs.com/skynet/p/3372855.html 这次分享的宗旨是——让大家学会创建与使用静态库.动态库,知道静态库与动态库的区别,知道使用的时候如何选择 ...
- GMap.Net开发之在地图上添加多边形
上一篇介绍了在GMap上添加自定义标签(GMapMarker),这篇介绍在GMap上添加多边形(GMapPolyogn),并且介绍如何在地图上画任意的多边形. 如果已经知道了多边形的各个点的位置,就可 ...
- 使用.NET Framework的配置文件app.config
在一般的项目中,为了使你的代码更加灵活,更方便调整,减少不必要的hard code,我们都在config中添加许多配置信息,一般可以选择.NET自带的配置文件形式app.config或者web项目中的 ...
- 用CocoaPods做iOS程序的依赖管理(转摘)
转摘自:http://blog.devtang.com/blog/2014/05/25/use-cocoapod-to-manage-ios-lib-dependency/ 文档更新说明 2012-1 ...
- js 上传文件后缀名的判断 var flag=false;应用
js 上传文件后缀名的判断 var flag=false;应用 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional// ...