1008 Fractal (2015年北京赛区网络赛G题)
来源:互联网 发布:网络控制器是干嘛的 编辑:程序博客网 时间:2024/05/16 18:11
1.题目描述:点击打开链接
2.解题思路:本题利用代数分析即可解决。通过观察可以发现,有竖线的地方的横坐标均满足0.5-0.5^n。因此可以事先求出n,如果发现恰好是0.5-0.5^n,输出-1,否则输出4*n。
3.代码:
#include<iostream>#include<algorithm>#include<cassert>#include<string>#include<sstream>#include<set>#include<bitset>#include<vector>#include<stack>#include<map>#include<queue>#include<deque>#include<cstdlib>#include<cstdio>#include<cstring>#include<cmath>#include<ctime>#include<cctype>#include<complex>#include<functional>#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;#define me(s) memset(s,0,sizeof(s))#define rep(i,n) for(int i=0;i<(n);i++)typedef long long ll;typedef unsigned int uint;typedef unsigned long long ull;typedef pair <ll, ll> P;const int N=4000+10;const double eps=1e-10;int dcmp(double x){ if(fabs(x)<eps)return 0; return x<0?-1:1;}int main(){ int T; scanf("%d",&T); while(T--) { double x; scanf("%lf",&x); int n=(int)floor(log(0.5-x)/log(0.5)); //printf("%d\n",n); double res=1.0; for(int i=0;i<n;i++) res*=0.5; res=0.5-res; //cout<<res<<endl; if(2*n-1<=1000&&dcmp(res-x)==0)puts("-1"); else { n=min(n,500); printf("%d\n",4*n); } }}
0 0
- 1008 Fractal (2015年北京赛区网络赛G题)
- 2015网络赛北京赛区G题(bfs+预处理)
- hihocoder #1234 : Fractal 北京赛区(2015)网络赛 (找规律)
- hihoCoder 1234 Fractal——ACM-ICPC国际大学生程序设计竞赛北京赛区(2015)网络赛
- 2015北京赛区网络赛模拟题
- 1005 Border Length (2015年北京赛区网络赛E题)
- 1001 The Cats' Feeding Spots (2015年北京赛区网络赛A题)
- 1002 Mission Impossible 6 (2015年北京赛区网络赛B题)
- 2015年ACM长春赛区网络赛G题
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 G题Bounce
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 G题Bounce
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 G Bounce (规律)
- 2015北京赛区网络赛 Boxes
- 2015北京网络赛题目: Fractal(打表+二分模拟)
- hihoCoder 北京网络赛 #1234 : Fractal
- HDU 5033 Building (2014年北京赛区网络赛B题)
- HDU 5035 Delivery (2014年北京赛区网络赛D题)
- HDU 5036 Explosion (2014年北京赛区网络赛E题)
- Git常用命令
- git 目录
- OAF开发基本知识点
- C++Primer第五版 练习11.4(解答)
- fork() vfork() return退出与exit退出 http://blog.chinaunix.net/uid-24261911-id-2620651.html
- 1008 Fractal (2015年北京赛区网络赛G题)
- Android开源工具库
- hdu 4349 Xiao Ming's Hope(C(n,m)的奇偶性)
- UI24_NSUserDefaults
- [BLE--SMP]蓝牙安全管理SM的配对方法
- og4j.properties配置详解
- 怎样安装haskell
- 《学习日记》CSS的盒子模型
- android开发中虚拟键盘的设置参数列表