原题链接:http://codeforces.com/gym/100431/attachments/download/2421/20092010-winter-petrozavodsk-camp-andrew-stankevich-contest-37-asc-37-en.pdf

题意

给你一个n,问你有多少a和x满足:x在a中二分会返回true,其中a的长度是n

题解

考虑到二分的过程不是向左就是向右,所以可以暴力搜索搞到若干序列,这些序列都是由向左或者向右组成的。枚举x,设向左的有i个,向右的有j个,这样的序列有cnt[i][j]个,表明整个序列,确定有i个数小于等于x,有j个数大于x,那么答案就是cnt[i][j] * (x ^ (i - 1)) * ((n - x) ^ j) * (n ^ (n - i - j)),当x等于0是需要特判一下。代码是队友用java写的。

代码

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*; public class Main {
static int n;
static BigInteger ans = new BigInteger("0");
static int xs[][] = new int[15][15];
static BigInteger tmp[] = new BigInteger[1010];
public Main() throws FileNotFoundException{
Scanner cin = new Scanner(new File("binary.in"));
PrintWriter cout = new PrintWriter(new File("binary.out"));
n = cin.nextInt();
tmp[0] = new BigInteger("1");
tmp[1] = new BigInteger(Integer.toString(n));
for(int i=2;i<=1000;i++) tmp[i] = tmp[i-1].multiply(tmp[1]);
if(n == 1){
cout.println("1");
}
else{
dfs(0,0,0,n);
for(int i=0;i<13;i++) for(int j=0;j<13;j++) if(xs[i][j] != 0){
if(i == 0){
BigInteger tmp3 = tmp[n - i - j - 1];
for(int k=1;k<=n;k++){
BigInteger tmp1 = new BigInteger(Integer.toString(k - 1));
tmp1 = tmp1.pow(j);
ans = ans.add(tmp1.multiply(tmp3).multiply(new BigInteger(Integer.toString(xs[i][j]))));
}
}
else{
for(int k=1;k<=n;k++){
BigInteger tmp1 = new BigInteger(Integer.toString(n-k));
tmp1 = tmp1.pow(j);
if(j == 0 && n == k) tmp1 = new BigInteger("1");
BigInteger tmp2 = new BigInteger(Integer.toString(k));
tmp2 = tmp2.pow(i-1);
BigInteger tmp3 = tmp[n-i-j];
ans = ans.add(tmp1.multiply(tmp2.multiply(tmp3)).multiply(new BigInteger(Integer.toString(xs[i][j]))));
}
}
}
cout.println(ans);
}
cin.close();
cout.close();
} void dfs(int x,int y,int l,int r){
if(l + 1 >= r){
xs[x][y]++;
return ;
}
int mid = (l + r) / 2;
dfs(x+1,y,mid,r);
dfs(x,y+1,l,mid);
} public static void main(String[] args) throws FileNotFoundException {
new Main();
}
}

Codeforces Gym 100431B Binary Search 搜索+组合数学+高精度的更多相关文章

  1. Codeforces Gym 100338H High Speed Trains 组合数学+dp+高精度

    原题链接:http://codeforces.com/gym/100338/attachments/download/2136/20062007-winter-petrozavodsk-camp-an ...

  2. Codeforces Gym 100231F Solitaire 折半搜索

    Solitaire 题目连接: http://codeforces.com/gym/100231/ Description 给你一个8*8棋盘,里面有4个棋子,每个棋子可以做一下某个操作之一: 1.走 ...

  3. codeforces gym #101161G - Binary Strings(矩阵快速幂,前缀斐波那契)

    题目链接: http://codeforces.com/gym/101161/attachments 题意: $T$组数据 每组数据包含$L,R,K$ 计算$\sum_{k|n}^{}F(n)$ 定义 ...

  4. Codeforces Gym 100418A A - A+-B java高精度

    A - A+-BTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.acti ...

  5. Codeforces 1237E. Balanced Binary Search Trees

    传送门 这一题是真的坑人,时间空间都在鼓励你用 $NTT$ 优化 $dp$...(但是我并不会 $NTT$) 看到题目然后考虑树形 $dp$ ,设 $f[i][0/1]$ 表示 $i$ 个节点的树,根 ...

  6. Binary Search 的递归与迭代实现及STL中的搜索相关内容

    与排序算法不同,搜索算法是比较统一的,常用的搜索除hash外仅有两种,包括不需要排序的线性搜索和需要排序的binary search. 首先介绍一下binary search,其原理很直接,不断地选取 ...

  7. [Swift]LeetCode701. 二叉搜索树中的插入操作 | Insert into a Binary Search Tree

    Given the root node of a binary search tree (BST) and a value to be inserted into the tree, insert t ...

  8. [LeetCode] Insert into a Binary Search Tree 二叉搜索树中插入结点

    Given the root node of a binary search tree (BST) and a value to be inserted into the tree, insert t ...

  9. [LeetCode] Search in a Binary Search Tree 二叉搜索树中搜索

    Given the root node of a binary search tree (BST) and a value. You need to find the node in the BST ...

随机推荐

  1. how to setting a i2c driver

    How to instantiate I2C devices============================== Unlike PCI or USB devices, I2C devices ...

  2. loj2276 「HAOI2017」新型城市化

    给出的图是一个二分图(显然--吗),一个图的最大团=其补图的最大独立集,因此二分图的最大独立集就是补图的最大团. 欲使补图最大团变大,则要最大独立集变大.二分图最大独立集=点数-最小点覆盖.最小点覆盖 ...

  3. [转] 查看 SELinux状态及关闭SELinux

    本文转载自: http://bguncle.blog.51cto.com/3184079/957315 查看SELinux状态: 1./usr/sbin/sestatus -v      ##如果SE ...

  4. python基础-爬虫

    爬虫引入 爬虫: 1 百度:搜索引擎 爬虫:spider   种子网站开始爬,下载网页,分析链接,作为待抓取的网页 分词 index:词--->某个结果 Page rank(1 网站很大(互链) ...

  5. 02 Java 的基本类型

    Java 的基本类型 Java 包括了八种基本类型,明细如下: Java 的基本类型都有对应的值域和默认值.byte,short,int,long,float以及double的值域依次扩大,前面的值域 ...

  6. [adb 学习篇] adb常用命令

    https://testerhome.com/topics/2565 Android 常用 adb 命令总结 针对移动端 Android 的测试, adb 命令是很重要的一个点,必须将常用的 adb ...

  7. ssh免密码登录远程服务器(不采用securecrt登录)

      http://blog.csdn.net/leexide/article/details/17252369       Linux/UNIX下使用ssh-keygen设置SSH无密码登录 标签:  ...

  8. linux各种版本查看方法

    1.linux内核版本 cat /proc/version Linux version 4.13.0-39-generic (buildd@lgw01-amd64-038) (gcc version ...

  9. chrome console.log API

    console.log(object [, object, ...]) Displays a message in the console. You pass one or more objects ...

  10. 配置CORS解决跨域调用—反思思考问题的方式

    导读:最近都在用一套完整的Java EE的体系做系统,之前都是用spring框架,现在弄这个Java EE,觉得新鲜又刺激.但,由于之前没有过多的研究和使用,在应用的过程中,也出现了不少的问题.累积了 ...