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. hdu 2608 (数论)

    hdu2608  0 or 1 题意:给你一个数N(N < 2^31), 问从 1--N 所有数的因子和S(N),求 S(N)%2 的值. 链接:http://acm.hdu.edu.cn/sh ...

  2. source 导入文件

    有时候,phpmyadmin 导入  是有大小限制的: 只可以用sql命令的source来导入文件

  3. uniqid()

    uniqid() 函数基于以微秒计的当前时间,生成一个唯一的 ID.

  4. Fire Net(深度优先搜索)

    ZOJ Problem Set - 1002 Fire Net Time Limit: 2 Seconds      Memory Limit: 65536 KB Suppose that we ha ...

  5. Hadoop 面试总结

    1.简要描述如何安装配置一个开源的hadoop,只描述即可,列出完整步骤. a.创建一个用户和用户组,用来管理hadoop项目 b.修改确定ip地址:vim /etc/sysconfig/networ ...

  6. 51nod1149 Pi的递推式

    基准时间限制:1 秒 空间限制:131072 KB 分值: 640 F(x) = 1 (0 <= x < 4) F(x) = F(x - 1) + F(x - pi) (4 <= x ...

  7. 【BZOJ】3998: [TJOI2015]弦论

    [题意]给定长度为n的小写字母字符串S,求第k小子串.n<=5*10^5. 给定T,T=0时不同位置的相同子串算一个,T=1时算多个. [算法]后缀自动机 [题解]对S建立SAM,T=0则每个节 ...

  8. 使用inline-block,使前面img,后面空div居中显示在一行后,导致当div中有内容时,div下移问题

    .pro_li img,.pro_sm{display: inline-block; *display:inline;*zoom:1;vertical-align: middle ;} 解决方法:使用 ...

  9. struts入门

    1.概念

  10. PHP提取url

    <?php $str = parse_url('http://localhost/?id=2&cd=2', PHP_URL_QUERY); ECHO $str; parse_str($s ...