看到题目要求x大,k小,我一开始想到的就是两个循环
while () {
x--;
} k++;
}
但是测试点全部超时,并且有几个wa;想不到原因。
附上错误的代码:
```cpp
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int x = 100, k = 1;
int s = 0;
int limit = 0;
int bestx = 1, bestk = n;
while (s != n) {
while (s != n) {
for (int i = 1; i <= 52; i++) {
for (int d = 1; d <= 7; d++) {
s += x + (d - 1) * k;
if (s == n) {
limit = 1;
break;
}
}
if (limit == 1) {
break;
}
}
if (limit == 1 && x > bestx) {
bestx = x;
bestk = k;
}
x--;
}
k++;
}
cout << bestx << endl;
cout << bestk << endl;
return 0;
}