# 计算巨魔通行费以安全通过

12

### 假设：

1. 输入两个参数：蛋糕税百分比（0到100之间的整数）和巨魔蛋糕退款。
2. 没有人，甚至没有巨魔，都想要被另一只巨魔部分吃掉的蛋糕。如果剩下的只是一块蛋糕，那么巨魔就会得到它。
3. 如果一个巨魔接受了蛋糕税，但是又不得不把所有蛋糕还给你（剩下的蛋糕比以前少或少），它就会生气并吃掉你和你的蛋糕。
4. 每个巨魔必须至少保留一个完整的蛋糕。
5. 您最多只能携带100个蛋糕。
6. 您需要结束当前所在的日子或所有7座桥梁的另一端。

### 例：

19个蛋糕-> 16-> 14-> 12-> 11-> 10-> 9-> 8
18个蛋糕-> 15-> 13-> 11-> 10-> 9-> 8-> 8（规则3）

``````input: 25 2
output: 19
``````

### 范例2：

90％蛋糕税，1个巨魔蛋糕退款

100个蛋糕-> 11-> 2-> 1（规则4）

``````input: 90 1
output: 0
``````

### 数据

``````27, 17, 13, 14, 15, 18, 20, 24, 53, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
47, 27, 20, 19, 19, 19, 24, 39, 48, 68, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0
67, 37, 28, 24, 23, 28, 27, 29, 50, 70, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
87, 47, 33, 29, 27, 28, 31, 44, 37, 72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
0, 57, 40, 34, 31, 29, 34, 34, 62, 74, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 67, 48, 39, 35, 38, 37, 49, 57, 76, 92, 0, 0, 0, 0, 0, 0, 0, 0, 0
0, 77, 53, 44, 39, 38, 47, 39, 59, 78, 94, 0, 0, 0, 0, 0, 0, 0, 0, 0
0, 87, 60, 49, 43, 39, 40, 54, 46, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
0, 97, 68, 54, 47, 48, 44, 44, 71, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
0, 0, 73, 59, 51, 48, 47, 59, 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0, 0, 0, 0, 0
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
``````

h，这就是为什么C＃不能拥有美好的事物

TwiNight

6

## CJam，46 43 41 39 38 36 33字节

``````100:H,{)_7{ea:i~H@m2\$*H/+@;}*>}#)
``````

``````rr]:A;
100:H,{)_7{A:i~H@m2\$*H/+@;}*>}#)
``````

``````100:H                                  "Push a 100 and save it in H.";
,                                 "Create a range (as an array) from 0 to 99.";
{                       }#       "Find the first index in [0,1,2,...,99] for which the
block produces a truthy (non-zero) value.";
)_                              "Increment and duplicate the current array element.";
7{                }*          "Execute the block seven times.";
ea:i                        "Push the command-line arguments as an array of strings
and convert each element to an integer";
~                       "Unwrap the array.";
H@                     "Push a 100 and rotate the stack to pull up
the first command line argument.";
m                    "Subtract (from 100).";
2\$                  "Copy the last iterations result.";
*H/               "Multiply and divide by 100, deducting tax.";
+              "Add the refund.";
@;            "Rotate top three stack elements, and discard the one that
has been pulled to the top. This always leaves the last
two results on the stack.";

>         "Make sure that the last result was less than the second
to last. Yields 0 or 1.";
)      "After the # search completes, we'll get -1 if no such
index exists, or one less than the desired number if it
does, so we can just increment.";
``````

1
@丹尼斯修复，谢谢！

@Dennis实际上节省了一个字节。我希望CJam有闭包，然后我可以在开始时定义一个块进行减税，并使用它，而不是使用两个变量。让我看看，也许我可以使用ARGV代替STDIN来保存一些内容。
Martin Ender 2014年

5

## CJam，44 40 38 37 35字节

``````l~U100:M),{{_M5\$-*M/3\$+_@<*}7*}=]W=
``````

``````100:M,{){_ea:i~M@-@*M/+_@<*}7*}#)
``````

`{}#`马丁的回答启发了我，不要把这作为我的主要方法。

``````25 2
``````

``````19
``````

``````15 14
``````

``````100
``````

``````l~                       "Read the two numbers, swap and convert tax to double";
U100:M),               "Push 0 and [0, 1, ... 100] to stack, storing 100 in M";
{  ...  }=     "Run this code for each element until top stack element is 1";
{...}7*       "Run this code block 7 times";
_                        "Copy the array element";
M5\$                    "Push 100 and a copy tax % to stack";
-*                  "Number = (100 - tax %) * Number";
M/                "Integer divide the number by 100";
_@<*         "Convert to 0 if refunded number > before tax one";
]W=  "Take the last element of the stack";
``````

Martin Ender 2014年

Optimizer

Martin Ender 2014年

@MartinBüttner-是的，我也是。
Optimizer

1
@Dennis-现在应该工作，附加的好处是缩短了2个字节的代码：D
Optimizer

4

## APL（39）

``````T R←⎕⋄⊃Z/⍨{⍵(⊢×>)R+⌊⍵×1-T÷M}⍣7¨Z←⍳M←100
``````

• `T R←⎕`：从键盘上读取两个数字，并将它们存储在`T`（税）和`R`（返回）中。
• `Z←⍳M←100`：将数字存储在`100``M`，并将所有数字存储在`1``100``Z`
• `{`... `}⍣7¨`：对于中的每个元素`Z`，请运行以下函数7次：
• `R+⌊1-T÷M`：计算需要支付多少蛋糕，
• `⍵(⊢×>)`：如果巨魔结出的蛋糕多于开始的数量，则将其乘以1；否则，将其乘以0。
• `⊃Z/⍨`：对于中的每个元素`Z`，请按该函数给出的编号进行复制。（因此，函数返回的所有数字都会`0`消失。）然后从该列表中选择第一项。如果列表最后为空，则给出`0`

3

# C，83字节

``````int cake(int perc_taken, int given_back)
{
int startcake = floor(100.f/perc_taken*given_back+1);
for(int i = 0; i < 6; i++)
{
startcake = ceil((startcake-given_back) * 100.f/(100 - perc_taken));
}
return startcake;
}
``````

``````n(int p,int g) {int s=100./p*g+1,i=0;for(;i++<6;){s=ceil((s-g)*100./(100-p));}return s;}
``````

``````n(int p,int g) {int s=100./p*g+1,i=0;for(;i++<6;){s=ceil((s-g)*100./(100-p));}return s>100?0:s;}
``````

91个字节。

2

# CJam，36个字节

``````q~:R100:H*\d:T/i){R-H*HT-/m]}6*_H)<*
``````

1

# C ++-202个字符

``````#include<iostream>
int main(){double p,g,c=1,i,r,t;std::cin>>p>>g;for(;c<101;c++){r=c;for(i=0;i<7;i++){t=(int)(r*(1-(p/100))+g);if(t>=r){r=-1;break;}r=t;}if(r!=-1)break;}r!=-1?std::cout<<c:std::cout<<0;}
``````

1

## APL，36

``````x y←⎕⋄101|1⍳⍨y<x×{y+⍵-⌈⍵×x}⍣6⍳x÷←100
``````

`x y←⎕`接受输入并分配给`x`（tax）和`y`（return）
`⍳x÷←100`除以`x`100，然后生成一个1到100的数组

`{y+⍵-⌈⍵×x}⍣6`调用“过桥”功能6次：
`⌈⍵×x`您拥有的蛋糕数量，税率乘以四舍五入（您支付的金额）
`⍵-`从您拥有的蛋糕数量中减去
`y+`添加退款

`x×`将数组乘以`x`
`y<`检查是否大于`y`

`1⍳⍨`找到第一次出现的索引`1`（true），`101`如果找不到则返回
`101|`mod 101

1

C 128

``````t,r,j,k,l,p;main(i){for(scanf("%d%d",&t,&r),i=101;k=--i;){for(j=8;--j>0;)(p=r+k*(100-t)/100)<k?k=p:j=0;j?0:l=i;}printf("%d",l);}
``````

``````int t,r,j,k,l,p;
main(int i)
{
for(scanf("%d%d",&t,&r),i=101;k=--i;)
{
for(j=8;--j>0;)
{
if((p=r+k*(100-t)/100)<k)
k=p;
else
j=0;
}
j?0:l=i;
}
printf("%d",l);
}
``````

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.