51nod1483-技巧&标记&思维-化学变换
2017-10-30 21:07
267 查看
https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1483
这道题看题解了,完全没有思路。。。。
数据范围1e5,所以就把所有当前容量的倍数做了标记,
对于小于他的数,如果结果是奇数,那么也把奇数的倍数做标记(可以证明他和原数的倍数永远不会重叠。),这点不容易想到。
这道题看题解了,完全没有思路。。。。
数据范围1e5,所以就把所有当前容量的倍数做了标记,
对于小于他的数,如果结果是奇数,那么也把奇数的倍数做标记(可以证明他和原数的倍数永远不会重叠。),这点不容易想到。
#include <bits/stdc++.h> using namespace std; const int maxn=1e5+300; int num[maxn]; int ste[maxn]; int n; void sol(int u){ int s=u; int temp=0; while(s<maxn){ num[s]+=temp; ste[s]++; s*=2; temp++; } int s2=u; temp=0; while(s2>1){ if(s2%2==1&&s2!=1){ int tem=temp+2; int s3=s2/2; s3*=2; while(s3<maxn){ num[s3]+=tem; ste[s3]++; s3*=2; tem++; } } int t=s2/2; temp++; num[t]+=temp; ste[t]++; s2/=2; } } int main() { int n,a; while(~scanf("%d",&n)){ memset(ste,0,sizeof(ste)); memset(num,0,sizeof(num)); for(int i=0;i<n;i++){ scanf("%d",&a); sol(a); } int ans=1e7; for(int i=0;i<maxn;i++){ if(ste[i]==n){ ans=min(ans,num[i]); } } printf("%d\n",ans); } return 0; }
相关文章推荐
- 51nod--1483--化学变换(思维)
- HDU:5256 序列变换(LIS-n*logn解法+思维+技巧)
- 51nod1483 化学变换
- HDU - 5248 序列变换 (二分&技巧)
- CodeForces 558 C. Amr and Chemistry && 51NOD 1483 化学变换(暴力 + 贪心)
- 1483 化学变换 (思维)
- 51Nod 1483 化学变换(思维+暴力)
- 51nod 1483 化学变换 (枚举+bfs or 枚举+技巧)
- Codeforces Round #383 (Div. 2) && Codeforces 742 B (标记技巧)
- 51nod 1483 化学变换(思维)
- 51nod 1483 化学变换【思维】
- CF911D:Inversion Counting(逆序数 & 思维)
- <Button>按钮点击变换,<EditText>组建功能,<TditView>文本跑马效果,滚动视图
- hdu 6016(思维技巧)@
- Asp.Net前台页面中有几种标记: < %= %>< %# %>< % %>< %@ %>
- <head>标记
- HDU 2795 Billboard (RMQ线段树&合并操作技巧)
- 用人类的思维方式去写更容易维护的代码——用<抽象-基础-逻辑>模式开发Java(Android)程序
- hpuoj 【1141】蜗牛爬树【模拟】&&【思维】
- Silverlight &WPF 技巧(一)DataGrid虚拟化加速不自动开启?