题意:初始串为一个1,每一步会将每个0改成10,每个1改成01,因此1会依次变成01,1001,01101001,……输入n(n<=1000),统计n步之后得到的串中,"00"这样的连续两个0出现了多少次。

分析:找规律,输出n等于20之前所有的结果

得到结论,i为奇数时,a[i] = a[i - 1] * 2 - 1; i为偶数时,a[i] = a[i - 1] * 2 + 1。

import java.util.*;
import java.math.BigInteger;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
BigInteger[] a = new BigInteger[1010];
a[1] = new BigInteger("0");
BigInteger one = new BigInteger("1");
BigInteger two = new BigInteger("2");
for(int i = 2; i <= 1000; ++i){
if(i % 2 == 1){
a[i] = a[i - 1].multiply(two).subtract(one);
}
else{
a[i] = a[i - 1].multiply(two).add(one);
}
}
while(sc.hasNextInt()){
int n = sc.nextInt();
System.out.println(a[n]);
}
} }

  

UVA - 1647 Computer Transformation(计算机变换)(找规律)的更多相关文章

  1. UVA 1647 Computer Transformation

    https://vjudge.net/problem/UVA-1647 题意: 开始有一个1,接下来每一步1变成01,0变成10 问n不之后00的个数 打表找规律 第3步之后: 如果第i步之后有x个字 ...

  2. UVa 12716 - GCD XOR(筛法 + 找规律)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  3. hdu_1041(Computer Transformation) 大数加法模板+找规律

    Computer Transformation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/ ...

  4. HDU 1041 Computer Transformation(找规律加大数乘)

    主要还是找规律,然后大数相乘 #include<stdio.h> #include<string.h> #include<math.h> #include<t ...

  5. UVa 11774 (置换 找规律) Doom's Day

    我看大多数人的博客只说了一句:找规律得答案为(n + m) / gcd(n, m) 不过神题的题解还须神人写.. We can associate at each cell a base 3-numb ...

  6. Computer Transformation(规律,大数打表)

    Computer Transformation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/ ...

  7. hdu4952 Number Transformation (找规律)

    2014多校 第八题 1008 2014 Multi-University Training Contest 8 4952 Number Transformation Number Transform ...

  8. 【数论,找规律】Uva 11526 - H(n)

    原来做过的题再看还是没想出来,看来当时必然没有真正理解.这次回顾感觉理解更透彻了. 网上的题解差不多都是一个版本,而且感觉有点扯.根据n=20猜出来的? 好吧哪能根据一个就猜到那么变态的公式.其实这题 ...

  9. GCD XOR UVA 12716 找规律 给定一个n,找多少对(a,b)满足1<=b<=a<=n,gcd(a,b)=a^b;

    /** 题目:GCD XOR UVA 12716 链接:https://vjudge.net/problem/UVA-12716 题意:给定一个n,找多少对(a,b)满足1<=b<=a&l ...

随机推荐

  1. Adroid ViewPage+GridView实现每页6个元素,三页滑动切换

    //}//public class MainActivity extends Activity {// private static final float APP_PAGE_SIZE = 16.0f ...

  2. 十三、web应用中路径总结

    1.路径的编写形式:1)<a href="/项目名/资源路径"></a>    <!--超链接--> <form action=" ...

  3. IDEA配置数据库连接失败的问题

    今天采用IDEA连接数据库失败了,有几个问题需要注意 首先笔者采用的数据库版本为8.0.17而IDEA自带版本是5.2.26大概,于是首先出现的问题是驱动不匹配,那么就需要换成我自己的版本,配置如下 ...

  4. window和document的区别理解,bom和dom的区别理解

    Window对象: 是整个BOM的核心,所有对象和集合都以某种方式回接到window对象.Window对象表示整个浏览器窗口,但不必表示其中包含的内容. Document对象: 实际上是window对 ...

  5. intent 跳转

    一.不需要返回值的跳转 Intent intent=new Intent(); intent.setClass(目前的acitivy.this, 目标activity.class); startAct ...

  6. [Codeforces #608 div2]1271C Shawarma Tent

    Description The map of the capital of Berland can be viewed on the infinite coordinate plane. Each p ...

  7. redis、mongodb、memcache安装好后设置开机自启动

    vim /etc/rc.d/rc.local /usr/local/mongodb/bin/mongod --smallfiles /usr/local/bin/redis-server/usr/lo ...

  8. 什么叫github

    git remote add origin https://github.com/huiwangui/git-demo.git:表示在本地仓库关联远程仓库(https://github.com/hui ...

  9. jumpserver手动配置文档

    1.环境  centos7.6   硬盘 200G  cpu  8核心  内存 32G (本地测试的时候,有报错,原因为虚拟机配置不够,此时为在pve虚拟化上面做的linux系统) 2.https:/ ...

  10. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 按钮:按钮标签

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...