您的位置:首页 > 其它

Codeforces #269 (Div. 2)C. MUH and House of Cards(数学:通项公式)

2014-09-27 01:41 369 查看
看起来很复杂,直接找通项公式即可

令x表示最底层的卡片数,令y表示有多少层

对于y层最少需要x = y*(y+1)/2张卡片数

则代码入下:

#include <bits/stdc++.h>
#define MAXN 1000010
#define LL long long
using namespace std;

bool vis[MAXN];

int main(void) {

//3*x == n+y;
LL n, x, y, tmp, cnt;
cin >> n;
x = n/3+1;
memset(vis, 0, sizeof(vis));
cnt = 0;
while(true) {
y = 3*x-n;
tmp = y*(y+1)>>1;
if(y > x || tmp>x) {
break;
}
else if(!vis[y]) {
++cnt;
vis[y] = true;
}
++x;
}
cout << cnt << endl;

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: