注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Boleyn Su's Blog

 
 
 
 
 

日志

 
 

USACO[Elite 2010 January Competition/gold]hayturn  

2010-06-11 19:54:31|  分类: 信息学 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

博弈论。

CODE:

/*

PROG: hayturn

LANG: C++

ID: boleyn.2

*/

/*

PROGRAM: $PROGRAM

AUTHOR: Su Jiao

DATE: 2010-6-9

DESCRIPTION:

TITLE: Taking Turns [John Pardon, 2009]

CONTENT:

Farmer John has invented a new way of feeding his cows. He lays out

N (1 <= N <= 700,000) hay bales conveniently numbered 1..N in a

long line in the barn. Hay bale i has weight W_i (1 <= W_i <=

2,000,000,000). A sequence of six weights might look something like:

        17 5 9 10 3 8

A pair of cows named Bessie and Dessie walks down this line after

examining all the haybales to learn their weights. Bessie is the

first chooser. They take turns picking haybales to eat as they walk

(once a haybale is skipped, they cannot return to it). For instance,

if cows Bessie and Dessie go down the line, a possible scenario is:

* Bessie picks the weight 17 haybale

* Dessie skips the weight 5 haybale and picks the weight 9 haybale

* Bessie picks the weight 10 haybale

* Dessie skips the weight 3 haybale and picks the weight 8 haybale

Diagrammatically:

Bessie   |      |

        17 5 9 10 3 8

Dessie       |      |

This scenario only shows a single skipped bale; either cow can skip

as many as she pleases when it's her turn.

Each cow wishes to maximize the total weight of hay she herself

consumes (and each knows that the other cow has this goal).

Furthermore, a cow will choose to eat the first bale of hay that

maximimizes her total weight consumed.

Given a sequence of hay weights, determine the amount of hay that

a pair of cows will eat as they go down the line of hay.

PROBLEM NAME: hayturn

INPUT FORMAT:

* Line 1: A single integer: N

* Lines 2..N+1: Line i+1 contains a single integer: W_i

SAMPLE INPUT (file hayturn.in):

6

17

5

9

10

3

8

OUTPUT FORMAT:

* Line 1: Two space-separated integers, the total weight of hay

        consumed by Bessie and Dessie respectively

SAMPLE OUTPUT (file hayturn.out):

27 17

*/

#include <fstream>

using std::ifstream;

using std::ofstream;

using std::endl;

#include <vector>

using std::vector;

 

class Application

{

      ifstream cin;

      ofstream cout;

      int N;

      vector<int> W;

      public:

      Application(const char* input,const char* output)

                        :cin(input),cout(output)

      {

                        std::ios::sync_with_stdio(false);

                        cin>>N;

                        W.resize(N);

                        for (vector<int>::iterator it=W.begin();

                                                   it!=W.end();it++)

                            cin>>*it;

      }

      ~Application()

      {

                    cin.close();

                    cout.close();

      }

      int run()

      {

          long long int max_me=0,max_not_me=0;

          for (int i=N-1;i>=0;i--)

              if (max_not_me+W[i]>=max_me)

              {

                 max_not_me+=W[i];

                 long long int swap=max_me;

                 max_me=max_not_me;

                 max_not_me=swap;

              }

          cout<<max_me<<" "<<max_not_me<<endl;         

          return 0;

      }

};

 

int main()

{

    Application app("hayturn.in","hayturn.out");

    return app.run();

}

 

  评论这张
 
阅读(411)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018