4 条回复
#include <iostream>
#include <string>
using namespace std;
int main()
{
int count = 0;
int n, k;
int i;
cin >> n >> k;
if (k >= n)
{
cout << n / k;
return 0;
}
for (i = 1; n > 0;)
{
if (n <= k)
{
break;
}
count++;
if (i % 2)
{
i--;
}
else
{
i++;
}
n -= (k + i);
}
cout << count;
system("pause");
}
我也很郁闷啊 10%
import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int tone = sc.nextInt(); int big = sc.nextInt(); int prv = 0; System.out.println(dpArr(tone, big, prv)); } sc.close(); } public static int dpArr(int tone, int big, int prv) { if (tone < big) { return 0; } if (tone == big) { if (big != prv) { return 1; } else { return 0; } } // decide the first heap int rs = -1; for (int i = 1; i <= tone; i++) { if (i != prv) { int next = dpArr(tone - i, big, i); //Here, fuck the bug , I am so foolish if (i >= big) { next += 1; } if (rs < next) { rs = next; } } } return rs; } } ..可怜考试出了点bug,忘记+1了。。。然后给的例子能过。。。 AC过不了,这是改好的。。。
添加回复