输入N和M,N是你手尚有的硬币数量,M为要求支付的金额。
接下来是N个数字,为硬币的面额。
注意相同金额的硬币可能有多个。输出要求V1+V2=M,V1<=V2,有多种结果取V1最小的。
面额不大于1000,所以从0到1000开始遍历,当前面额银币有,用掉,用掉的必须小于需要支付的金额。
再看,剩下金额的硬币手里是否有,有责直接输出,结束。
如果行不通,当然,拿出来的硬币要放回去。
1 |
|
输入N和M,N是你手尚有的硬币数量,M为要求支付的金额。
接下来是N个数字,为硬币的面额。
注意相同金额的硬币可能有多个。输出要求V1+V2=M,V1<=V2,有多种结果取V1最小的。
面额不大于1000,所以从0到1000开始遍历,当前面额银币有,用掉,用掉的必须小于需要支付的金额。
再看,剩下金额的硬币手里是否有,有责直接输出,结束。
如果行不通,当然,拿出来的硬币要放回去。
1 | #include <iostream> |
给出学生人数N和学科数K。
接着是N行,每一行是每个学生报名的科目。
输出每一门课有几个学生报名,分别是谁。
1 | #include <iostream> |
地铁环状线两点之间的距离为t,最小值为t或则是周长-t。(t为按起点到终点由小到大,大减小而来)
1 | #include <iostream> |
重点在Eva is trying to make her own color stripe out of a given one. She would like to keep only her favorite colors in her favorite order by cutting off those unwanted pieces and sewing the remaining parts together to form her favorite color stripe.
从给的例子可以看出,要求保持喜欢颜色的先后顺序,并且使最后条纹的长度尽可能长。(喜欢的颜色可以不出现)
以
6
5 2 3 1 5 6
12 2 2 4 1 5 5 6 3 1 1 5 6
为列,6表示总共6种颜色,5表示喜欢5中颜色,之后是喜欢颜色的优先级顺序。
12表示原条纹的颜色排列,之后依次是12种颜色。
1 | #include <iostream> |
给一串数字,子序列之和为M。
For each test case, print i-j in a line for each pair of i ≤ j such that Di + … + Dj = M. Note that if there are more than one solution, all the solutions must be printed in increasing order of i.
如果没有符合条件,使子序列之和-M最小。
If there is no solution, output i-j for pairs of i ≤ j such that Di + … + Dj >M with (Di + … + Dj −M) minimized. Again all the solutions must be printed in increasing order of i.
1 | #include <iostream> |