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. jetBrains 插件开发第一课-- 在主菜单栏新增一个菜单

    环境搭建完了,接下来可以开始写代码了: 1.新建 plugin 项目 2.编辑 plugin.xml,修改一下里面的插件名那些信息,该文件的配置项可以看这里:plugin.xml 其中比较关键的有一个 ...

  2. (转) 使用vivado创建工程 1

    此文全文转自:http://svenand.blogdrive.com/archive/169.html#.WaUV9IiGNPY  ,非常感谢! 本人在vivado 2015.4版本测试! When ...

  3. 使用nginx做反向代理

    很多同学喜欢用nginx做反向代理访问某些网站,原因大家都懂的,今天老高记录一下如何使用nginx做反向代理以及如何配置和优化nginx的反向代理. 准备工作 首先,你需要一个稳定的国外的便宜的VPS ...

  4. Jugs(回溯法)

    ZOJ Problem Set - 1005 Jugs Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge In ...

  5. js_beautifier && css_beautifier for emeditor

    // // Unpacker for Dean Edward's p.a.c.k.e.r, a part of javascript beautifier // written by Einar Li ...

  6. 在Windows下安装MongoDB

    概述 读者可以通过本文来学习在Windows操作系统上安装MongoDB. 从2.2版本开始,Mongo DB不在支持Windows XP.请使用最近的windows来安装最近发布的MongoDB.本 ...

  7. 【leetcode 简单】第六题 有效的括号

    给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效. 有效字符串需满足: 左括号必须用相同类型的右括号闭合. 左括号必须以正确的顺序闭合. 注意空字符串可被认 ...

  8. typeof运算符

    javascript中typeof用来判断一个变量或表达式的数据类型. typeof 返回值有六种可能: "number," "string," "b ...

  9. CounterBreach安装测试的全部过程

    CounterBreach安装测试的全部过程 1安装数据库审计的网关 Admin进入 Impcfg初始化 选择网关 是否替换另一个网关? 否 是否改变默认管理口 设置管理口地址 192.168.1.2 ...

  10. HZ与Jiffies

    2.4 内核定时器 内核中许多部分的工作都高度依赖于时间信息.Linux内核利用硬件提供的不同的定时器以支持忙等待或睡眠等待等时间相关的服务.忙等待时,CPU 会不断运转.但是睡眠等待时,进程将放弃C ...