zoj 3627#模拟#枚举
2014-08-26 20:06
387 查看
Treasure Hunt IITime Limit: 2 Seconds Memory Limit: 65536 KB
There are n cities(1, 2, ... ,n) forming a line on the wonderland. city i and city i+1 are adjacent and their distance is 1. Each city has many gold coins. Now, Alice and her friend Bob make a team to go treasure hunting. They starts at city p, and they want to get as many gold coins as possible in T days. Each day Alice and Bob can move to adjacent city or just stay at the place, and their action is independent. While as a team, their max distance can't exceed M.
They can always get the gold coins of the starting city, even if T=0
Author: LI, Chao Contest: ZOJ Monthly, July 2012
题意 转自:http://blog.csdn.net/cscj2010/article/details/7819110
题意:n个城市排成一行,每个城市中有vi个金币。两个人同时从同一个个城市出发,单位时间能走到相邻城市。
到达城市获取金币不耗时间,且任意时刻两人距离不可以超过m,问t个时间他们最多能获得多少金币。
如果 m >= t * 2,两个人两个方向一直走
否则 两人一直向两边走指导相距m,注意,若m为奇数,则某人要停走一天。
然后维持距离同时向左向右枚举剩余天数
There are n cities(1, 2, ... ,n) forming a line on the wonderland. city i and city i+1 are adjacent and their distance is 1. Each city has many gold coins. Now, Alice and her friend Bob make a team to go treasure hunting. They starts at city p, and they want to get as many gold coins as possible in T days. Each day Alice and Bob can move to adjacent city or just stay at the place, and their action is independent. While as a team, their max distance can't exceed M.
Input
The input contains multiple cases. The first line of each case are two integers n, p as above. The following line contain n interger,"v1 v2 ... vn" indicate the gold coins in city i. The next line is M, T. (1<=n<=100000, 1<=p<=n, 0<=vi<=100000, 0<=M<=100000, 0<=T<=100000)Output
Output the how many gold coins they can collect at most.Sample Input
6 3 1 2 3 3 5 4 2 1
Sample Output
8
Hint
At day 1: Alice move to city 2, Bob move to city 4.They can always get the gold coins of the starting city, even if T=0
Author: LI, Chao Contest: ZOJ Monthly, July 2012
题意 转自:http://blog.csdn.net/cscj2010/article/details/7819110
题意:n个城市排成一行,每个城市中有vi个金币。两个人同时从同一个个城市出发,单位时间能走到相邻城市。
到达城市获取金币不耗时间,且任意时刻两人距离不可以超过m,问t个时间他们最多能获得多少金币。
如果 m >= t * 2,两个人两个方向一直走
否则 两人一直向两边走指导相距m,注意,若m为奇数,则某人要停走一天。
然后维持距离同时向左向右枚举剩余天数
#include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> #include<algorithm> #include<cmath> #include<queue> #include<map> #include<vector> #define N 100005 #define M 15 #define mod 1000000007 #define mod2 100000000 #define ll long long #define maxi(a,b) (a)>(b)? (a) : (b) #define mini(a,b) (a)<(b)? (a) : (b) using namespace std; int n,p; ll v ; ll tot; ll sum ; int m,t; int t1,t2; void ini() { int i; tot=0; memset(sum,0,sizeof(sum)); for(i=1;i<=n;i++){ //scanf("%lld",&v[i]); cin>>v[i]; sum[i]=sum[i-1]+v[i]; } scanf("%d%d",&m,&t); } void solve() { int i,j,o; if(m/2>=t) { i=max(1,p-t); j=min(n,p+t); tot=sum[j]-sum[i-1]; return ; } t1=min(t,m/2); t2=t-t1; i=max(1,p-t); j=min(n,p+t1); tot=sum[j]-sum[i-1]; for(o=0;o<=t2;o++){ i=max(1,p-t1-o); if(m%2==1 && o!=0){ j=max(p+t1,p+t1+t2-2*o+1); j=min(n,j); } else{ j=max(p+t1,p+t1+t2-2*o); j=min(n,j); } tot=max(tot,sum[j]-sum[i-1]); } j=min(n,p+t); i=max(1,p-t1); tot=max(tot,sum[j]-sum[i-1]); for(o=0;o<=t2;o++){ if(m%2==1 && o!=0){ i=min(p-t1,p-t1-t2+2*o-1); i=max(1,i); } else{ i=min(p-t1,p-t1-t2+2*o); i=max(1,i); } j=min(n,p+t1+o); // printf(" o=%d i=%d j=%d sum=%I64d\n",o,i,j,sum[j]-sum[i-1]); tot=max(tot,sum[j]-sum[i-1]); } //tot=v[p]; // i=max(p-t,1); //if(i==1){ // tot=sum[] // } // j=min(p+1,n); } int main() { //freopen("data.in","r",stdin); // scanf("%d",&T); // for(int cnt=1;cnt<=T;cnt++) // while(T--) while(scanf("%d%d",&n,&p)!=EOF) { //if(g==0 && b==0 &&s==0) break; ini(); solve(); //printf("%lld\n",tot); cout<<tot<<endl; } return 0; }
相关文章推荐
- zoj 3627#模拟#枚举
- ZOJ 3715 投票选国王 (枚举+贪心+模拟)
- ZOJ 1354(枚举,模拟)
- ZOJ 2656 Travel Around Country(模拟,枚举)
- ZOJ-3715-Kindergarten Election(贪心 枚举 模拟)
- zoj 3327 Friend Number 枚举 分类讨论 模拟
- 状态压缩(2)+模拟枚举(2)--poj3279(能力题)
- ZOJ - 3804 YY's Minions(模拟)
- ZOJ3804_YY's Minions 模拟
- ZOJ 3939The Lucky Week<模拟/暴力>
- ZOJ 1111 Poker Hands --复杂模拟
- ZOJ 3838 Infusion Altar(数学啊 模拟啊 这么挫的代码你见过吗?)
- ZOJ 3883 Scan Code 模拟
- Codeforces Round #444 (Div. 2) C. Solution for Cube 枚举、模拟、魔方
- zoj 2971 Give Me the Number (模拟)
- ZOJ 3601 Unrequited Love(模拟)
- hdu4662-枚举|搜索&模拟-Scaring the Birds
- zoj 3829(逆波兰表达式、模拟)
- ZOJ 3804 YY's Minions (简单模拟)
- ZOJ-3914-Semantic Version【模拟】