Problem Statement

     Wolf Sothe and Cat Snuke are playing a card game. The game is played with exactly 100 cards. The cards are numbered from 1 to 100. The game is played as follows:
  1. First, Cat Snuke chooses the goal: an integer N between 1 and 100, inclusive.
  2. Then, Wolf Sothe chooses exactly K of the 100 cards and gives the chosen cards to Snuke.
  3. Next, Cat Snuke may throw some of those K cards away. He may choose any subset of cards he was given, possibly none or all of them.
  4. Finally, Cat Snuke may write minus signs onto any subset of the cards he still holds. For example, if he currently has the cards {1,3,4,7}, he may alter them to {-1,3,4,-7}.

At the end of the game, Snuke computes the sum of the numbers on his cards (with the added minus signs). Snuke wins the game if the sum is exactly equal to the goal number N. Otherwise, Sothe wins.

Your task is to help Wolf Sothe win the game. We are now in step 2 of the game. You are given the int N chosen by Snuke and the int K that specifies the number of cards you have to give to Snuke. Choose those K cards in such a way that Snuke will be unable to win the game. If you can do that, return a vector <int> with K elements: the numbers on the chosen cards. If there are multiple solutions, you may return any of them. If there is no solution, return an empty vector <int> instead.

Definition

    
Class: WolfCardGame
Method: createAnswer
Parameters: int, int
Returns: vector <int>
Method signature: vector <int> createAnswer(int N, int K)
(be sure your method is public)

Limits

    
Time limit (s): 2.000
Memory limit (MB): 256
Stack limit (MB): 256

Constraints

- N will be between 1 and 100, inclusive.
- K will be between 1 and 15, inclusive.

Examples

0)  
    
20
4
Returns: {1, 2, 3, 4 }
If we give Snuke cards with numbers 1, 2, 3, and 4 on them, the largest sum he can form is 1+2+3+4 = 10. Thus, he cannot reach N=20 and we win.
1)  
    
40
1
Returns: {39 }
 
2)  
    
97
6
Returns: {7, 68, 9, 10, 62, 58 }
 
3)  
    
2
12
Returns: {33, 69, 42, 45, 96, 15, 57, 12, 93, 9, 54, 99 }
 

题意:从1到100挑出K个数字,挑出的数字可正可负,求一种总和不为N的方案.

分析:如果N为奇数,那么选前K个最小的偶数一定不会组成奇数.类似的,如果N不是3的倍数,那么选择前K个最小的3的倍数的数字;4,5,6同理,但7的时候,如果K=15,最后一个数字是105不在100内,满足该特殊情况的数字是60,那么前面添加一个1,结果是{1,7,14,21,28,35,42,49,56,63,70,77,84,91,98}

官方题解

class WolfCardGame {
public:
vector <int> createAnswer( int N, int K ) {
vector<int> ret;
if (N == 60 && K == 15) {
ret.push_back (1);
K = 14;
}
for (int i=2; i<=7; ++i) {
if (N % i != 0) {
for (int j=0, v=i; j<K; ++j, v+=i) {
ret.push_back (v);
}
break;
}
}
return ret;
}
};

  

数学 SRM 690 Div1 WolfCardGame 300的更多相关文章

  1. topcoder srm 690 div1 -3

    1.给定一个数字$N$,从1到100的100个数字中选出$K$个数字(设为集合$S$),然后对$S$进行如下运算: (1)删除$S$中的某些数字:(可以删除0个数字) (2)将$S$中的某些数字取为它 ...

  2. Topcoder SRM 643 Div1 250<peter_pan>

    Topcoder SRM 643 Div1 250 Problem 给一个整数N,再给一个vector<long long>v; N可以表示成若干个素数的乘积,N=p0*p1*p2*... ...

  3. Topcoder Srm 726 Div1 Hard

    Topcoder Srm 726 Div1 Hard 解题思路: 问题可以看做一个二分图,左边一个点向右边一段区间连边,匹配了左边一个点就能获得对应的权值,最大化所得到的权值的和. 然后可以证明一个结 ...

  4. 图论 SRM 674 Div1 VampireTree 250

    Problem Statement      You are a genealogist specializing in family trees of vampires. Vampire famil ...

  5. SRM 583 DIV1

    A 裸最短路. class TravelOnMars { public: int minTimes(vector <int>, int, int); }; vector<int> ...

  6. SRM 598 DIV1

    A 只有3种情况:200以上的单独装,3个100的装一起,某两个u,v装一起且u+v<=300, 所以做法是从大到小判断每个大小的最大能与它装一起的是谁,最后剩下100的特判. B 第一轮如果未 ...

  7. SRM 590 DIV1

    转载请注明出处,谢谢viewmode=contents">http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlov ...

  8. topcoder srm 490 div1

    problem1 link 首先每$n*m$一定是一个循环,所以只需要考虑时间$[0,n*m-1]$即可.这个期间一共出现了$n$个,第i个的出现时间为$m*i$,离开的时间为$\left \lcei ...

  9. topcoder srm 440 div1

    problem1 link 二分答案,然后计算总时间.跟$T$比较确定要增大答案还是减小答案. problem2 link 可以看作是以‘*’所在位置为根的树.所以每个非根节点都有一个父节点. 那么每 ...

随机推荐

  1. 初探微信小程序

    摘要 最近闲下来了,就准备了解下微信小程序的内容.首先从目录结构开始吧. 创建项目 工具下载:https://mp.weixin.qq.com/debug/wxadoc/dev/devtools/do ...

  2. Excel—身份证生日提取

    一.只有18位的身份证号码 如: 身份证号 330682199302264000 41120019890823729X 231081199002256839 131101198203154666 36 ...

  3. CF memsql Start[c]UP 2.0 B

    CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...

  4. Vue in 2016

    原文链接:Vue in 2016 Vue 作者尤雨溪对 Vue 在 2016 年的总结以及未来的展望 现在已经是2016的尾声了!在这过去的12个月里,Vue的持续增长速度已经超过了我的预期--这个项 ...

  5. Wampserver主机服务配置方法

    一.更改根目录  1.左键”www目录”路径更改Wampserver安装好后,“www目录”默认为X:\wamp\www,也就是wampserver安装目录下的www文件夹.实际使用中,默认设置往往不 ...

  6. 开大你的音响,感受HTML5 Audio API带来的视听盛宴

    话说HTML5的炫酷真的是让我爱不释手,即使在这个提到IE就伤心不完的年代.但话又说回来,追求卓越Web创造更美世界这样高的追求什么时候又与IE沾过边儿呢?所以当你在看本文并且我们开始讨论HTML5等 ...

  7. Linux Swap分区设定

    因为准备在linux上面安装Oracle数据库,据说swap分区小于4G容易失败,天啦噜的我连swap分区是啥都不是非常清楚, 大概有个印象吧,但先搞大了再说. 测试证明Ubuntu14默认的swap ...

  8. Win10环境下安装Vmware+Ubuntu14 注意点

    下载相关软件正常安装完成后可能会碰到以下两个问题,这里备注一下,备用 1.Ubuntu的root密码设置 2.Vmware网络连接设成桥接之后,Win10可以ping通Ubuntu,但Ubuntu无法 ...

  9. 【ASP.NET】利用Nuget打包package——GUI方式

    GUI方式 通过GUI的方式,可以下载如下的软件 NuGetPackageExplorer   打包dll 1.打开软件,在Package Content处点击右键 ,选择Add Lib 2.在lib ...

  10. 关于git的简单实用命令

    时代在进步啊,现在已经不是svn的时代了,好多人都在使用git.所以自己也稍微学习了下git的使用. 常见的通过git提交代码步骤: git status :查看文件状态 :该命令显示你工程内修改的所 ...