E - Bus Number

最近感觉打CF各种车祸。。。。。感觉要反思一下,

上次读错题,这次想当然地以为18!肯定暴了longlong 而没有去实践,

这个题我看到就感觉是枚举每个数字的个数,但是我觉得算得时候会爆longlong

就想用大数,但是我去看别人交的全部都是C++,就感觉是不是有别的方法,

想了半天感觉时间来不及了就强行上了个java,结果时间来不及。。。

以后写题首先要读清楚题目,其次不要想当然,要去实践!!!!!!!!!!! 真的很烦。

import java.math.BigInteger;
import java.util.*;
public class Main {
static long n;
static int cnt[] = new int[10];
static int num[] = new int[10];
static long f[] = new long[20];
static long ans = 0;
static long one = 1000000000;
static long base = one * one;
public static void main(String arg[]) { f[0] = 1;
for(int i = 1; i <= 18; i++) {
f[i] = f[i - 1] * i;
} Scanner in = new Scanner(System.in);
n = in.nextLong();
if(n == base) {
System.out.println("18");
} else {
while(n > 0) {
int ret = (int)(n % 10);
cnt[ret]++;
n /= 10;
} for(int i = 0; i < 10; i++) {
if(cnt[i] > 0) {
num[i] = 1;
cnt[i]--;
}
} dfs(0);
System.out.println(ans);
}
in.close();
} public static void dfs(int p) {
//System.out.println("#####");
ans += cal();
for(int i = p; i <= 9; i++) {
if(cnt[i] == 0) continue;
cnt[i]--;
num[i]++;
dfs(i);
num[i]--;
cnt[i]++;
}
}
public static long cal() {
int sum = 0;
long ans = 0, ret = 0;
for(int i = 0; i <= 9; i++) sum += num[i];
ans = f[sum]; for(int i = 0; i <= 9; i++) {
if(num[i] > 0)ans /= f[num[i]];
} if(num[0] > 0) {
ret = f[sum - 1];
ret /= f[num[0] - 1];
for(int i = 1; i <= 9; i++) {
if(num[i] > 0) {
ret /= f[num[i]];
}
}
}
return ans - ret; }
}

Codeforces Round #491 (Div. 2) E - Bus Number + 反思的更多相关文章

  1. Codeforces Round #491 (Div. 2)

    Codeforces Round #491 (Div. 2) https://codeforces.com/contest/991 A #include<bits/stdc++.h> us ...

  2. 【Codeforces】Codeforces Round #491 (Div. 2) (Contest 991)

    题目 传送门:QWQ A:A - If at first you don't succeed... 分析: 按照题意模拟 代码: #include <bits/stdc++.h> usin ...

  3. Codeforces Round #436 (Div. 2)C. Bus 模拟

    C. Bus time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input out ...

  4. Codeforces Round #369 (Div. 2) A. Bus to Udayland 水题

    A. Bus to Udayland 题目连接: http://www.codeforces.com/contest/711/problem/A Description ZS the Coder an ...

  5. Codeforces Round #484 (Div. 2) B. Bus of Characters(STL+贪心)982B

    原博主:https://blog.csdn.net/amovement/article/details/80358962 B. Bus of Characters time limit per tes ...

  6. Codeforces Round #369 (Div. 2) A. Bus to Udayland (水题)

    Bus to Udayland 题目链接: http://codeforces.com/contest/711/problem/A Description ZS the Coder and Chris ...

  7. Codeforces Round #427 (Div. 2) B. The number on the board

    引子: A题过于简单导致不敢提交,拖拖拉拉10多分钟还是决定交,太冲动交错了CE一发,我就知道又要错过一次涨分的机会.... B题还是过了,根据题意目测数组大小开1e5,居然蒙对,感觉用vector更 ...

  8. Codeforces Round #369 (Div. 2) A. Bus to Udayland【字符串/二维字符数组求连起来的座位并改为其他字符】

    A. Bus to Udayland time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. Codeforces Round #585 (Div. 2) B. The Number of Products(DP)

    链接: https://codeforces.com/contest/1215/problem/B 题意: You are given a sequence a1,a2,-,an consisting ...

随机推荐

  1. codeforces 691E 矩阵快速幂+dp

    传送门:https://codeforces.com/contest/691/problem/E 题意:给定长度为n的序列,从序列中选择k个数(可以重复选择),使得得到的排列满足xi与xi+1异或的二 ...

  2. Linux下安装python-2.7 先zlib

    2018-04-25 发布 Linux下安装python-2.7  python 1.1k 次阅读  ·  读完需要 25 分钟 1 安装依赖的库 yum -y install python-deve ...

  3. 「Django」rest_framework学习系列-API访问跨域问题

    #以中间件方式解决API数据访问跨域问题1.API下新建文件夹下写PY文件a.引入内置类继承: from django.middleware.common import MiddlewareMixin ...

  4. javaFX8初探(环境搭建)

    1:下载java8  Oracle官网2:下载eclipse4.4 eclipse官网3:安装e(fx)clipse插件 http://download.eclipse.org/efxclipse/u ...

  5. CF821 C. Okabe and Boxes 栈模拟

    Link 题意:给出操作,如果当前出栈操作使得出栈序列非顺序,可以在此之前自由排序栈中所有数,问最少排几次. 思路:已经出栈到第x个元素时,每次需要排序的操作后,能够保证前x元素出栈有序,否则说明该操 ...

  6. elasticsearch ik中文分词器的安装配置使用

    安装步骤  https://github.com/medcl/elasticsearch-analysis-ik 以插件形式安装: [elsearch@localhost elasticsearch- ...

  7. JSP分页之结合Bootstrap分页插件进行简单分页

    结合Bootstrap的分页插件实现分页,其中策略是每次显示5个按钮,然后根据当前页的不同来进行不同的显示: 1. 当前页<3,如果当前页大于5页就显示前五页,不然就显示1~totalPage. ...

  8. How to read source code[repost]

    https://github.com/benjycui/benjycui.github.io/blob/master/posts/how-to-read-open-source-javascript- ...

  9. B - GuGuFishtion(莫比乌斯 欧拉函数 预处理mu函数的欧拉函数的模板)

    题目链接:https://cn.vjudge.net/contest/270608#problem/B 题目大意:题目中说,就是对欧拉函数的重新定义的一种函数的求和. 证明方法: AC代码: #inc ...

  10. 可能是是最全的Springboot基础视频分享,告别无视频可学

    一头扎进SpringBoot视频教程 SpringBoot入门 2017年-张志君老师-SpringBoot(新增) 欢迎关注我的微信公众号:"Java面试通关手册" 回复关键字& ...