[Offer收割]编程练习赛38
漏写的数字
#pragma comment(linker, "/STACK:102400000,102400000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<iostream>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<functional>
//#include<bits/stdc++.h>
using namespace std;
typedef long long lint; int cmp(const void * x, const void * y) {
#define datatype int
datatype dx = *((datatype *)(x)), dy = *((datatype *)(y));
//x < y
return dx > dy ? : -;
#undef datatype
} char str[];
int s[]; int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
std::ios::sync_with_stdio(), cin.tie();
cin >> str;
bool f, f1;
int n = strlen(str);
for (int i = ; i < n; i++) s[i] = str[i] - '';
int ans;
f = true, f1 = false;
int b = s[];
int ptr = ;
while (ptr < n) {
b++;
if (b < ) {
if (s[ptr] == b) {
ptr++;
continue;
} else {
if (f1) {
f = false;
break;
} else {
f1 = true;
ans = b;
}
}
} else {
if (s[ptr] == b / && s[ptr + ] == b % ) {
ptr += ;
continue;
} else {
if (f1) {
f = false;
break;
} else {
f1 = true;
ans = b;
}
}
}
}
if (f && f1) {
cout << ans << endl;
return ;
}
f = true, f1 = false;
b = s[] * + s[];
ptr = ;
while (ptr < n) {
b++;
if (b < ) {
if (s[ptr] == b) {
ptr++;
continue;
} else {
if (f1) {
f = false;
break;
} else {
f1 = true;
ans = b;
ptr++;
}
}
} else {
if (s[ptr] == b / && s[ptr + ] == b % ) {
ptr += ;
continue;
} else {
if (f1) {
f = false;
break;
} else {
f1 = true;
ans = b;
}
}
}
}
if (f && f1) {
cout << ans << endl;
return ;
}
return ;
}
扁平化管理
#pragma comment(linker, "/STACK:102400000,102400000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<iostream>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<functional>
//#include<bits/stdc++.h>
using namespace std;
typedef long long lint; int cmp(const void * x, const void * y) {
#define datatype int
datatype dx = *((datatype *)(x)), dy = *((datatype *)(y));
//x < y
return dx > dy ? : -;
#undef datatype
} lint a[][];
const lint inf = 0x7FFFFFFFFFFFFFFF; int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
std::ios::sync_with_stdio(), cin.tie();
for (int i = ; i < ; i++) {
for (int j = ; j < ; j++) {
lint aaa = , tmp = ;
if (i < j - ) continue;
for (int k = ; k < j; k++) {
aaa *= (i - k + );
tmp += aaa;
if (tmp > 1e18) break;
}
if (tmp > 1e18) a[i][j] = inf;
else a[i][j] = tmp;
}
}
lint n, l;
cin >> n >> l;
bool f = false;
for (int i = ; i < ; i++) {
for (int j = ; j < min((lint), l + ); j++) {
if (a[i][j] >= n && !f) {
cout << i << endl;
f = true;
}
}
}
if (!f) {
if (l == ) cout << n - << endl;
else if (l == ) {
lint tmp = (lint)sqrt(n);
if (tmp * tmp + >= n) cout << tmp << endl;
else cout << tmp + << endl;
} else {
for (int i = ;; i++) {
if (i < l - ) continue;
lint aaa = , tmp = ;
for (int k = ; k < l; k++) {
aaa *= (i - k + );
tmp += aaa;
if (tmp > 1e18) break;
}
if (tmp > n) {
cout << i << endl;
break;
}
}
}
}
return ;
}
小球染色
动态规划:dp[i][j]表示决定了前i个的颜色,最后j个颜色相同的方法数。
#pragma comment(linker, "/STACK:102400000,102400000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<iostream>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<functional>
//#include<bits/stdc++.h>
using namespace std;
typedef long long lint; int cmp(const void * x, const void * y) {
#define datatype int
datatype dx = *((datatype *)(x)), dy = *((datatype *)(y));
//x < y
return dx > dy ? : -;
#undef datatype
} lint dp[][];
const int mod = ; int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
std::ios::sync_with_stdio(), cin.tie();
int n, m, k;
cin >> n >> m >> k;
memset(dp, , sizeof(dp));
dp[][] = m;
for (int i = ; i <= n; i++) {
for (int j = ; j < k; j++) {
dp[i + ][j + ] = (dp[i + ][j + ] + dp[i][j]) % mod;
dp[i + ][] = (dp[i + ][] + dp[i][j] * (m - )) % mod;
}
}
lint ans = ;
for (int i = ; i < k; i++) ans = (ans + dp[n][i]) % mod;
cout << ans << endl;
return ;
}
三角形面积和2
[Offer收割]编程练习赛38的更多相关文章
- HihoCoder1652 : 三角形面积和2([Offer收割]编程练习赛38)(几何)(不会几何,占位)
描述 如下图所示,在X轴上方一共有N个三角形.这些三角形的底边与X轴重合,底边上两个顶点的坐标分别是(Li, 0)和(Ri, 0),底边的对顶点坐标是(Xi, Yi).其中Li ≤ Xi ≤ Ri 且 ...
- HihoCoder1651 : 小球染色([Offer收割]编程练习赛38)(DP的优化)
描述 小Ho面前有N个小球排成了一排.每个小球可以被染成M种颜色之一. 为了增强视觉效果,小Ho希望不存在连续K个或者K个以上的小球颜色一样. 你能帮小Ho计算出一共有多少种不同的染色方法么? 例如N ...
- HihoCoder1650 : 扁平化管理([Offer收割]编程练习赛38)(二分)
描述 小Hi的公司包括CEO在内一共有N名员工.这N名员工的上下级关系形成树形结构,CEO处于树根,普通员工处于叶子节点. 现在公司希望管理扁平化,要求树形结构中的层级不超过L层.此外,假设A是B的直 ...
- HihoCoder1649 : 漏写的数字([Offer收割]编程练习赛38)(模拟题)
描述 小A今年刚上幼儿园,正在学习写100以内的数字.幼儿园的老师留了一项作业,要求小A从某个100以内的数X开始一直写到另一个100以内的数Y(Y - X > 1). 不过粗心的小A在作业中漏 ...
- hihocoder [Offer收割]编程练习赛4
描述 最近天气炎热,小Ho天天宅在家里叫外卖.他常吃的一家餐馆一共有N道菜品,价格分别是A1, A2, ... AN元.并且如果消费总计满X元,还能享受优惠.小Ho是一个不薅羊毛不舒服斯基的人,他希望 ...
- hihocoder [Offer收割]编程练习赛61
[Offer收割]编程练习赛61 A:最小排列 给定一个长度为m的序列b[1..m],再给定一个n,求一个字典序最小的1~n的排列A,使得b是A的子序列. 贪心即可,b是A的子序列,把不在b中的元素, ...
- [Offer收割]编程练习赛46
[Offer收割]编程练习赛46赛后题解 A.AEIOU 分析
- [Offer收割]编程练习赛97
链接 [https://hihocoder.com/contest/offers97/problems] 题意 题目1 : 放置矩形 时间限制:10000ms 单点时限:1000ms 内存限制:256 ...
- hihoCoder[Offer收割]编程练习赛1题目解析
题目1 : 九宫 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描写叙述 小Hi近期在教邻居家的小朋友小学奥数.而近期正好讲述到了三阶幻方这个部分,三阶幻方指的是将1~9不反 ...
随机推荐
- Higher-Order Functions and Lambdas
https://kotlinlang.org/docs/reference/lambdas.html
- Java JPA通过hql语句查询数据
import javax.persistence.PersistenceContext; import javax.persistence.Query; public class StudentSer ...
- python mysql连接池
话不多说,直接撸代码 # coding=utf-8 from DBUtils.PooledDB import PooledDB import pymysql as mysql import trace ...
- 01 c++常见面试题总结
https://www.cnblogs.com/yjd_hycf_space/p/7495640.html C++常见的面试题 http://c.tedu.cn/workplace/217749. ...
- 51nod1183 编辑距离【动态规划】
编辑距离,又称Levenshtein距离(也叫做Edit Distance),是指两个字串之间,由一个转成另一个所需的最少编辑操作次数.许可的编辑操作包括将一个字符替换成另一个字符,插入一个字符,删除 ...
- centos7关闭防火墙以及查看防火墙状态
1.关闭firewall:systemctl stop firewalld.service #停止firewall systemctl disable firewalld.service #禁止fir ...
- hdu 3001(三进制状压)
题目 解法 看到这道题,我们就会想到旅行商问题.但是这里每一个点可以经过最多两次,所以我们用三进制表示就好了. 代码 #include <iostream> #include <cs ...
- jsp页面获取服务器Ip地址等数据
废话不多说,直接上代码 <%@ page language="java" import="java.util.*" pageEncoding=" ...
- (15)Spring Boot使用Druid和监控配置【从零开始学Spring Boot】
Spring Boot 系列博客] 更多查看博客:http://412887952-qq-com.iteye.com/blog Spring Boot默认的数据源是:org.apache.tomcat ...
- RMAN主要命令 show,list,crosscheck,delete详解
Oracle RMAN 的 show,list,crosscheck,delete命令整理 Oracle RMAN 的 show,list,crosscheck,delete命令整理 1.SHOW命 ...