Codeforces #269 (Div. 2)C. MUH and House of Cards(数学:通项公式)
2014-09-27 01:41
369 查看
看起来很复杂,直接找通项公式即可
令x表示最底层的卡片数,令y表示有多少层
对于y层最少需要x = y*(y+1)/2张卡片数
则代码入下:
令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; }
相关文章推荐
- C. MUH and House of Cards(Codeforces Round #269)
- C. MUH and House of Cards (题目类型很有特点,存一下以便学习)
- CodeForces 471C - MUH and House of Cards(推导)
- C. MUH and House of Cards(数论规律题)
- codeforces 471C MUH and House of Cards 数论
- Codeforces 471C MUH and House of Cards【找规律+二分】
- Codeforces Round #269 (Div. 2) D题 MUH and Cube Walls(KMP)
- 【Codeforces Round 269 (Div 2)B】【简单构造】MUH and Sticks 数值升序输出三种可能编号序
- Codeforces Round #269 (Div. 2) B. MUH and Important Things
- MUH and House of Card
- 【Codeforces Round 269 (Div 2)A】【简单讨论】MUH and Sticks 6根木棍拼动物
- Codeforces #269 (Div. 2)D. MUH and Cube Walls(KMP)
- Codeforces Round #269 (Div. 2) A. MUH and Sticks
- 【Codeforces Round 269 (Div 2)C】【暴力】MUH and Sticks 纸牌搭楼n张牌恰好搭楼数
- Codeforces Round #234 (Div. 2):B. Inna and New Matrix of Candies
- Codeforces Round #251 (Div. 2) C. Devu and Partitioning of the Array
- codeforces 235 div2 A. Vanya and Cards
- Codeforces Round #259 (Div. 2) C - Little Pony and Expected Maximum (数学期望)
- Codeforces Round #251 (Div. 2) C. Devu and Partitioning of the Array
- codeforces#234_div2_B Inna and New Matrix of Candies