思路:这题对于其他能退出所有值的情况比较好像,唯一不能确定的是XXOXXOXXOXX这个形式的序列,其中XX表示未知,O表示已知。

我们令num[1]=0,那么num[4]=sum[3]-sum[2]+num[1];

可以递推,num[i]=sum[i-1]-sum[i-2]+num[i-3],(i%3==1)。

这样求出来的每个num值就是相对于num[1]的值。

假使某个num[i]<0,表示第i个数相对于num[1]为负数,题目要求每个数都大于等于0,所以num[1]>=(-num[i])。

所以num[1]>=max(-num[i]).

同理可以求出所有相对于num[2]的值。

#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<string>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pb push_back
#define mp make_pair
#define Maxn 100010
#define Maxm 200010
#define LL __int64
#define Abs(x) ((x)>0?(x):(-x))
#define lson(x) (x<<1)
#define rson(x) (x<<1|1)
#define inf 100000
#define lowbit(x) (x&(-x))
#define clr(x,y) memset(x,y,sizeof(x))
#define Mod 1000000007
using namespace std;
int num[Maxn],sum[Maxn],val[Maxn];
int main()
{
int n,m,i,j,x1,x2,x;
while(scanf("%d",&n)!=EOF){
for(i=;i<=n;i++)
scanf("%d",num+i);
for(i=;i<=n;i++)
scanf("%d",sum+i);
num[]=sum[]-sum[];
for(i=;i<=n;i++) if(num[i-]>=){
num[i]=sum[i-]-sum[i-]+num[i-];
}
num[n-]=sum[n-]-sum[n];
for(i=n-;i>=;i--) if(num[i+]>=){
num[i]=sum[i+]-sum[i+]+num[i+];
}
if(num[]>=) num[]=sum[]-num[];
if(num[]>=) num[]=sum[]-num[];
for(i=;i<=n;i++) if(num[i-]>=&&num[i-]>=){
num[i]=sum[i-]-num[i-]-num[i-];
}
x1=x2=;
for(i=;i<=n;i+=) if(num[i]<){
val[i]=val[i-]-sum[i-]+sum[i-];
x1=max(x1,-val[i]);
}
for(i=;i<=n;i+=) if(num[i]<){
val[i]=val[i-]-sum[i-]+sum[i-];
x2=max(x2,-val[i]);
}
scanf("%d",&m);
while(m--){
scanf("%d",&x);
x++;
if(num[x]>=){
printf("%d\n",num[x]);
continue;
}
if(x%==){
printf("%d\n",sum[]-x2+val[x]);
continue;
}
printf("%d\n",sum[]-x1+val[x]);
}
}
return ;
}

2013 长沙网络赛J题的更多相关文章

  1. 2013长沙网络赛H题Hypersphere (蛋疼的题目 神似邀请赛A题)

    Hypersphere Time Limit: 1 Second       Memory Limit: 32768 KB In the world of k-dimension, there's a ...

  2. 2013 ACM/ICPC 长沙网络赛J题

    题意:一个数列,给出这个数列中的某些位置的数,给出所有相邻的三个数字的和,数列头和尾处给出相邻两个数字的和.有若干次询问,每次问某一位置的数字的最大值. 分析:设数列为a1-an.首先通过相邻三个数字 ...

  3. HDU 4800/zoj 3735 Josephina and RPG 2013 长沙现场赛J题

    第一年参加现场赛,比赛的时候就A了这一道,基本全场都A的签到题竟然A不出来,结果题目重现的时候1A,好受打击 ORZ..... 题目链接:http://acm.hdu.edu.cn/showprobl ...

  4. 2013 长沙网络赛 B 题 Bizarre Routine

    题解 http://blog.csdn.net/u010257508/article/details/11936129 #include <iostream> #include <c ...

  5. HDU 4762 Cut the Cake (2013长春网络赛1004题,公式题)

    Cut the Cake Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  6. HDU 4758 Walk Through Squares (2013南京网络赛1011题,AC自动机+DP)

    Walk Through Squares Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Oth ...

  7. HDU 4759 Poker Shuffle(2013长春网络赛1001题)

    Poker Shuffle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  8. HDU 4768 Flyer (2013长春网络赛1010题,二分)

    Flyer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  9. HDU 4751 Divide Groups (2013南京网络赛1004题,判断二分图)

    Divide Groups Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

随机推荐

  1. SQLServer2005 提示 '其他会话正在使用事务的上下文'

    MSDN上看了一下说是sql server 2005不支持在分布式事务处理中存在指向本地的链接服务器(环回链接服务器) 这个是官方的回答 个人认为,应该是在事务中,使用了链接服务器访问进行跨库访问引起 ...

  2. android ExpandAbleListView控件

    ExpandAbleListView控件 1.API对ExpandAbleListView的解释:

  3. MES取所有部门的函数实例

    USE [ChangHong]GO/****** Object: UserDefinedFunction [dbo].[FN_GetDeptCode] Script Date: 04/26/2016 ...

  4. 集合类 Contains 方法 深入详解 与接口的实例

    .Net 相等性:集合类 Contains 方法 深入详解 http://www.cnblogs.com/ldp615/archive/2009/09/05/1560791.html 1.接口的概念及 ...

  5. winform系统自动登录实现

    转载:http://www.cnblogs.com/wuhuacong/archive/2012/08/21/2648339.html 系统自动登录有时候很必要,在用户自己绝对信任的电脑上,自动登录对 ...

  6. cdoj 24 8球胜负(eight) 水题

    8球胜负(eight) Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/24 ...

  7. Android 开发之异常处理篇(一):SDK Manager 闪退的解决方法

    这个问题困扰了我很久,之前没解决,就放一放.后来我又专门拿了一个下午来找解决方法,终于搞定! 我的解决方法是修改 android.bat,直接指定java.exe所在位置,不用去调用find_java ...

  8. TP复习13

    ## ThinkPHP 3.1.2 模板的使用技巧#讲师:赵桐正微博:http://weibo.com/zhaotongzheng 本节课大纲:一.模板包含 <include file=&quo ...

  9. c++笔试题两道,求解当中一道

    1.Implement a functionthat prints the numbers from 1 to 100.But for multiples of three(3) print &quo ...

  10. Xcode常见的编译、运行等错误的解决

    Xcode常见的编译.运行等错误的解决 项目没找到Info.plist的错误 The solution for this particular instance of the error was “I ...