C. MUH and House of Cards (题目类型很有特点,存一下以便学习)
2014-12-25 19:37
477 查看
http://codeforces.com/contest/471/problem/C
首先看数据范围: n高达10^12,首先第一反应就是肯定有公式,而且随着层数的增高,木棍数会急速增大。
所以此题很常规的一个思路就是:
从一层开始枚举,直到木棍数大于给出的n。
构成最高层时用的最少数量的card数目: n*(3n+1) / 2(因为每层数目为3n-1)
AC Code:
总结:
遇到题目先看懂题,从小数据进行逐步分析。(一般ACM题目很少要写if else,一般都是有比较通用一点的公式的)
首先看数据范围: n高达10^12,首先第一反应就是肯定有公式,而且随着层数的增高,木棍数会急速增大。
所以此题很常规的一个思路就是:
从一层开始枚举,直到木棍数大于给出的n。
构成最高层时用的最少数量的card数目: n*(3n+1) / 2(因为每层数目为3n-1)
AC Code:
1 // 2 // main.cpp 3 // C++_text01 4 // 5 // Created by songjs on 14-10-11. 6 // Copyright (c) 2014年 songjs. All rights reserved. 7 // 8 9 #include <stdio.h> 10 #include <string.h> 11 #include <math.h> 12 #include <stdlib.h> 13 #include <iostream> 14 #include <algorithm> 15 using namespace std; 16 #define LL long long 17 18 int main() 19 { 20 //freopen("in.txt","r",stdin); 21 LL n; 22 while(scanf("%I64d",&n)!=EOF){ 23 int num = 0; 24 for(LL i=1;i*(3*i+1)/2 <=n ;i++){ 25 if((n-i*(3*i+1)/2 )% 3 == 0)num++; 26 } 27 printf("%d\n",num); 28 } 29 return 0; 30 }
总结:
遇到题目先看懂题,从小数据进行逐步分析。(一般ACM题目很少要写if else,一般都是有比较通用一点的公式的)
相关文章推荐
- CodeForces 471C - MUH and House of Cards(推导)
- Codeforces #269 (Div. 2)C. 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 数论
- C. MUH and House of Cards(Codeforces Round #269)
- MUH and House of Card
- 流体力学学习笔记1(Two-way of coupling of fluids to rigid and deformable solids and shells)
- Lengths of Primitive Java and C++ Data Types on Linux and Windows 32-bit/64-bit (Linux和Windows上Java和C++基本数据类型的长度对比32位/64位)
- JavaScript学习笔记-- undefined and null 数据类型分析
- 《Two Dozen Short Lessons in Haskell》学习(九)- Types of Curried Forms and Higher Order Functions
- MVC3+EF4.1学习系列(八)-----利用Repository and Unit of Work重构项目
- 发一下关于公司的HOUSE OF HELLO 关于假货网站的声明吧
- Principle of Computing (Python)学习笔记(3) probability +Objects and reference + tic_tac_toe
- Andrew Ng机器学习公开课笔记 -- Mixtures of Gaussians and the EM algorithm
- [CF 471C] MUH and House of Cards
- 优秀课件笔记之重要类型旅游地介绍与分析Introduction and Analysis of Tourist Destinationsof Destinations
- Science论文"Clustering by fast search and find of density peaks"学习笔记
- 基本类型算法题目学习(EPI)
- 腾讯php程序员面试题目,供大家学习一下