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. Problem D. Country Meow 2018ICPC南京

    n个点求出最小圆覆盖所有点 退火算法不会,不过这题可以用三分套三分写 x轴y轴z轴各三分 #include <cstdio> #include <cstring> #inclu ...

  2. Linux iptables:场景实战一

    <Linux iptables:规则原理和基础>和<Linux iptables:规则组成>介绍了iptables的基础及iptables规则的组成,本篇通过实际操作进行ipt ...

  3. 「Django」与mysql8连接的若干问题

    1.setting配置 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', #数据库驱动名 'NAME': 'my_tes ...

  4. go defer注意点,很容易出错的!!!

    1:defer是在return之前执行的  函数返回的过程是这样的:先给返回值赋值,然后调用defer表达式,最后才是返回到调用函数中 返回值 = xxx 调用defer函数 空的return fun ...

  5. (转)IO复用,AIO,BIO,NIO,同步,异步,阻塞和非阻塞 区别

    本文来自:https://www.cnblogs.com/aspirant/p/6877350.html?utm_source=itdadao&utm_medium=referral,非常感谢 ...

  6. 4.redis设计与实现--跳跃表

    1.跳跃表由两个结构体构成: 2.总结:

  7. PHP提取链接批量下载

    2014年年初的时候,曾经受委托完成一个视频网站,那时最大的技术障碍是一个大视频比如500MB,在一个带宽环境不怎么快的服务器(比如1Mbps)上提供播放的问题. 这里会遇到两种情况,第一种情况是客户 ...

  8. 分析nginx日志脚本之python

    为了对每个月的切割过的30个日志文件统计出访问最多的ip地址进行排序,整理了下面的脚本,主要思路是处理每一个日志文件的ip排序,最后进行字典合并,计算出月ip排序. #!/usr/bin/env py ...

  9. Logitech K810 + Ubuntu

    The Logitech K810 is a nice keyboard, but it does not work with Ubuntu out of the box. Still contrar ...

  10. 提高效率!15款最好的 Bug 跟踪应用程序

    当涉及到开发项目时,其中比较重要的事情是它需要某​​种形式的错误和问题跟踪工具来发现和解决问题,否则会浪费大量的时间. 此外,你总是要标签应用来标示那些悬而未决的问题,而这种分期执行的项目进度将帮助您 ...