Codeforces Round #491 (Div. 2) 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 + 反思的更多相关文章
- Codeforces Round #491 (Div. 2)
Codeforces Round #491 (Div. 2) https://codeforces.com/contest/991 A #include<bits/stdc++.h> us ...
- 【Codeforces】Codeforces Round #491 (Div. 2) (Contest 991)
题目 传送门:QWQ A:A - If at first you don't succeed... 分析: 按照题意模拟 代码: #include <bits/stdc++.h> usin ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #427 (Div. 2) B. The number on the board
引子: A题过于简单导致不敢提交,拖拖拉拉10多分钟还是决定交,太冲动交错了CE一发,我就知道又要错过一次涨分的机会.... B题还是过了,根据题意目测数组大小开1e5,居然蒙对,感觉用vector更 ...
- 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 ...
- 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 ...
随机推荐
- PhpStorm 快速查找文件 `Ctrl`+`Shift`+`N`
PhpStorm 快速查找文件 `Ctrl`+`Shift`+`N`
- CF835 D DP
所有所有阶回文串的个数.对于一个k阶回文串,定义为:它的左右两侧相同且是k-1阶回文串 显然高阶回文串由低阶构成,那么枚举长度,从左到右遍历,dp[l][r]代表从l到r串最大的阶数,cnt[i]记录 ...
- 非法字符:"\ufeff"
Eclipse项目导入IDEA可能遇到这样的问题 ,原因就是: 带BOM的UTF-8」和「无BOM的UTF-8」 方法一.用Notepad++把文件转成无BOM的UTF-8 另存为,替换原来的文件 方 ...
- PHP扩展开发--02.包裹第三方的扩展
背景 也许最常见的PHP扩展是那些包裹第三方C库的扩展.这些扩展包括MySQL或Oracle的数据库服务库,libxml2的 XML技术库,ImageMagick 或GD的图形操纵库. 在本节中,我们 ...
- ubuntu11下安装文件
1.ubuntu11下安装.run文件 首先右键单击这个文件,在properties-permissions那里选择允许以程序执行(打钩Allow executing file as program) ...
- 【转载】iPhone系统概览
iPhone OS OverviewiPhone系统概览iPhone OS comprises the operating system and technologies that you use t ...
- node、npm及node_modules中依赖的版本更新
好久没用node了,想重新拾起来发现node还有相关模块的版本都太低了,使用npm install全是报版本低的警告. 这里记录一下,版本管理和node_modules更新的方法. 我用的是Windo ...
- oracle01--单表查询
1. 基本(基础)查询 1.1. 基本查询语法 基本查询是指最基本的select语句. [语法] [知识点]如何使用工具进行查询 在plsql developer中打开查询窗口(执行sql语句): 执 ...
- virtualenv搭建虚拟环境
最近因为项目需要,要在CentOS 7 上搭建一套开发环境,虽说Python的背后有着庞大的开源社区支持,但是有一个缺点就是每个包的质量都参差不齐,如果我们在工作服务器上去测试安装每个包,就会造成整个 ...
- C# 怎么显示中文格式的日期、星期几
//该语句显示的为英文格式DateTime.Now.DayOfWeek.ToString(); //显示中文格式星期几 "星期" + DateTime.Now.ToString(& ...