记第一次SRM (SRM489 div2)

来源:互联网 发布:制作项目进度表 软件 编辑:程序博客网 时间:2024/05/17 07:55

一年前知道了TC

注册账号

发现不会用

就拿了别人的代码测试

下次登录时发现被封号了

就放弃了

昨天看到有SRM

又想做一下

下午装插件、熟悉环境

在练习房做题

以为div1的题简单些

结果杯具了。。。

后来才知道div2的题简单

 

8点比赛开始

250分的题是一个字符串搜索

不过平时很少用string

现在到处找系统函数搜索

先把STL里面的find和string的find搞混了

后来花了很久的时间才弄明白

我对C++太不熟悉了

平时都用C,偶尔用下STL

判断前缀我竟然也搜索

别人是直接用substr再判断是否相等

判断后缀写的更丑

用了多次搜索。。。

在最后几分钟提交了代码

等待challenge的到来

challenge中怀着无比紧张的心情

害怕被人cha了

还好没人cha掉我的代码

主要是我的代码写的太丑了

估计没人愿意看

system testing阶段

看到很多代码挂了很是担心

最后还是挂了

0分!

分析错误原来是没考虑后缀长度大于主串长度

还是实力不够啊

后面看500分的题

原来是枚举

一会儿就把代码写出来

然后在练习房直接AC

早知道就看看500分的题

原来SRM没我想的那么难

原来我的实力还是很弱

 

 虽然0分,rate也有955

 

附SRM div2 500 BuyingFlowers

Problem Statement

    Teddy loves roses and Tracy loves lilies. They wish to plant these flowers in a large garden.



However, the only florist in town sells these flowers in packets which are represented by vector <int>s roses and lilies. The i-th packet contains roses[i] roses and lilies[i] lilies. Each packet can be bought only once.



Teddy and Tracy wish to buy some flowers and arrange them into a rectangular grid. This grid must be arranged such that each cell contains exactly one flower, and any two cells which share an edge must contain different kinds of flowers. Additionally, Teddy and Tracy must use all the flowers they buy.



Teddy and Tracy love square-shaped grids, so they wish to buy a set of packets such that they can arrange the flowers into the most square-like grid possible. More precisely, they wish to arrange the flowers into an R x C grid, where R and C are positive integers, such that |R-C| (|R-C| denotes the absolute value of R-C) is minimized. Return this minimum absolute value, or -1 if no valid arrangement exists.

Definition

    Class:BuyingFlowersMethod:buyParameters:vector <int>, vector <int>Returns:intMethod signature:int buy(vector <int> roses, vector <int> lilies)(be sure your method is public)     

Constraints

-roses and lilies will contain the same number of elements, between 1 and 16, inclusive.-Each element of roses and lilies will be between 0 and 10000, inclusive.-The total number of flowers in each packet represented by roses and lilies will be greater than 0.

Examples

0)     
{2, 4}
{4, 2}
Returns: 1
Buying all the packets to get 6 roses and 6 lilies, they can create a 3 x 4 grid with the following arrangement:
  RLRL  LRLR  RLRL
The difference of the height and the width of this arrangement is 1.1)     
{2, 7, 3}
{3, 4, 1}
Returns: 0
Buying the first and the third packets, they can create the following square arrangement:
  RLR  LRL  RLR
2)     
{4, 5, 2, 1}
{6, 10, 5, 9}
Returns: -1
No valid grid can be created.3)     
{1, 208, 19, 0, 3, 234, 1, 106, 99, 17}
{58, 30, 3, 5, 0, 997, 9, 615, 77, 5}
Returns: 36

 

用二进制枚举2^n种选择情况

矩形内r和l的数量差小于等于1

找出min|i-j|使i*j=r+l

再更新结果

 

250:

原创粉丝点击