当前位置: 首页 > news >正文

hdu 4430 Yukari's Birthday 枚举+二分

注意会超long long

开i次根号方法,te=(ll)pow(n,1.0/i);

 

Yukari's Birthday

Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3262    Accepted Submission(s): 695

Problem Description
Today is Yukari's n-th birthday. Ran and Chen hold a celebration party for her. Now comes the most important part, birthday cake! But it's a big challenge for them to place n candles on the top of the cake. As Yukari has lived for such a long long time, though she herself insists that she is a 17-year-old girl. To make the birthday cake look more beautiful, Ran and Chen decide to place them like r ≥ 1 concentric circles. They place k i candles equidistantly on the i-th circle, where k ≥ 2, 1 ≤ i ≤ r. And it's optional to place at most one candle at the center of the cake. In case that there are a lot of different pairs of r and k satisfying these restrictions, they want to minimize r × k. If there is still a tie, minimize r.
 
Input
There are about 10,000 test cases. Process to the end of file. Each test consists of only an integer 18 ≤ n ≤ 10 12.
 
Output
For each test case, output r and k.
 
Sample Input
18 111 1111
 
Sample Output
1 17 2 10 3 10
 
Source
2012 Asia ChangChun Regional Contest

 

  1 #include<cstdio>
  2 #include<cstdlib>
  3 #include<cmath>
  4 #include<cstring>
  5 #include<string>
  6 #include<iostream>
  7 #define maxi(a,b) (a)>(b)?(a):(b)
  8 #define mini(a,b) (a)<(b)?(a):(b)
  9 #define N 1000005
 10 #define mod 10000
 11 #define ll long long
 12 
 13 using namespace std;
 14 
 15 ll n;
 16 ll ans;
 17 ll r,k;
 18 ll rr,kk;
 19 
 20 void ini()
 21 {
 22     ans=n-1;
 23     r=1;
 24     k=n-1;
 25 }
 26 
 27 void cal3(ll x)
 28 {
 29     ll te,d;
 30     te=1+4*x;
 31     d=sqrt(te);
 32     if(d*d==te){
 33         kk=(d-1);
 34         if(kk%2==0){
 35             kk/=2;
 36             if(kk*2<ans){
 37                 ans=kk*2;
 38                 k=kk;r=2;
 39             }
 40         }
 41     }
 42 }
 43 
 44 ll cal(ll a,ll cnt)
 45 {
 46     ll re=1;
 47     while(cnt)
 48     {
 49         if(cnt&1){
 50             re=(re*a);
 51             cnt--;
 52         }
 53         cnt/=2;
 54         a=a*a;
 55     }
 56     return re;
 57 }
 58 
 59 int cal2(ll a,ll en,ll now)
 60 {
 61     ll i;
 62     for(i=en;i>=1;i--){
 63         now+=cal(a,i);
 64         if(now>n) return 0;
 65     }
 66     if(now<n-1) return 2;
 67     if(now==n-1 || now==n){
 68         if(a*(en+1)<ans){
 69             ans=a*(en+1);
 70             r=en+1;
 71             k=a;
 72         }
 73         else{
 74             if(a*(en+1)==ans && (en+1)<r){
 75                 r=en+1;
 76                 k=a;
 77             }
 78         }
 79     }
 80     return 2;
 81 }
 82 
 83 void solve()
 84 {
 85     ll te,temp;
 86     cal3(n);
 87     cal3(n-1);
 88     ll i;
 89     for(i=3;i<=45;i++){
 90         //temp=cal(2ll,i);
 91         //if(temp>n) break;
 92         te=(ll)pow(n,1.0/i);
 93         for(kk=te;kk>=2;kk--){
 94             temp=cal(kk,i);
 95             if(temp>n) continue;
 96             if(cal2(kk,i-1,temp)==2){
 97                 break;
 98             }
 99         }
100     }
101 }
102 
103 void out()
104 {
105     printf("%I64d %I64d\n",r,k);
106 }
107 
108 int main()
109 {
110     //freopen("data.in","r",stdin);
111     //scanf("%d",&T);
112    // while(T--)
113     while(scanf("%I64d",&n)!=EOF)
114     {
115         ini();
116         solve();
117         out();
118     }
119     return 0;
120 }

 

转载于:https://www.cnblogs.com/njczy2010/p/4031976.html

相关文章:

  • 机器学习平台跃迁,AI中台才是大势所趋
  • Android-Universal-Image-Loader 图片异步加载类库的使用
  • Gradle DSL method not found: 'compile()'
  • 我在开发第一个Swift App过程中学到的四件事
  • 【小小决斗】我看你不顺眼很久了,快来和我一决高下!
  • [NHibernate]条件查询Criteria Query
  • SQL-12 获取所有部门中当前员工薪水最高的相关信息,给出dept_no, emp_no以及其对应的salary...
  • DataGridView隔行显示不同的颜色
  • 获取随机数,要求长度一致的字符串格式
  • 润乾集算报表多样性数据源之动态源
  • springsecurity 源码解读 之 RememberMeAuthenticationFilter
  • 算法:四舍六入五成双 ,保留三位有效数字
  • VS 编码规范---- 代码注释设置
  • Tuxedo入门学�
  • mybatis的collection查询问题以及使用原生解决方案的结果
  • 【140天】尚学堂高淇Java300集视频精华笔记(86-87)
  • 【Redis学习笔记】2018-06-28 redis命令源码学习1
  • 2017-09-12 前端日报
  • Javascript编码规范
  • Java多线程(4):使用线程池执行定时任务
  • JDK 6和JDK 7中的substring()方法
  • jquery cookie
  • Kibana配置logstash,报表一体化
  • Logstash 参考指南(目录)
  • quasar-framework cnodejs社区
  • SAP云平台运行环境Cloud Foundry和Neo的区别
  • XForms - 更强大的Form
  • 使用阿里云发布分布式网站,开发时候应该注意什么?
  • 思考 CSS 架构
  • 学习JavaScript数据结构与算法 — 树
  • 智能合约开发环境搭建及Hello World合约
  • #数学建模# 线性规划问题的Matlab求解
  • (a /b)*c的值
  • (补)B+树一些思想
  • (二)Linux——Linux常用指令
  • (分布式缓存)Redis哨兵
  • (附源码)springboot炼糖厂地磅全自动控制系统 毕业设计 341357
  • (十八)devops持续集成开发——使用docker安装部署jenkins流水线服务
  • (转)Linux NTP配置详解 (Network Time Protocol)
  • (转)socket Aio demo
  • .bat批处理(十一):替换字符串中包含百分号%的子串
  • .naturalWidth 和naturalHeight属性,
  • .NET 线程 Thread 进程 Process、线程池 pool、Invoke、begininvoke、异步回调
  • .net网站发布-允许更新此预编译站点
  • .NET业务框架的构建
  • .NET中的Event与Delegates,从Publisher到Subscriber的衔接!
  • .net中生成excel后调整宽度
  • /boot 内存空间不够
  • [BSGS算法]纯水斐波那契数列
  • [BZOJ 3282] Tree 【LCT】
  • [CentOs7]图形界面
  • [CSS]中子元素在父元素中居中
  • [HDOJ4911]Inversion
  • [LeetCode] 148. Sort List 链表排序
  • [LeetCode]—Permutations II 求全排列(有重复值)