方向

#pragma comment(linker, "/STACK:102400000,102400000")
#ifndef ONLINE_JUDGE
#include "stdafx.h"
#else
#include<bits/stdc++.h>
#endif
using namespace std;
typedef long long lint;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef queue<int> QI;
typedef map<int, int> MII; void makedata() {
freopen("input.txt", "w", stdout);
fclose(stdout);
}
int min_(int x, int y) {
if (fabs(x) == fabs(y)) return fabs(x);
return fabs(x) < fabs(y) ? x : y;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//makedata();
std::ios::sync_with_stdio(), cin.tie();
int a, b, x, y;
cin >> a >> b;
x = b - a;
if (x < ) x += ;
y = x - ;
cout << min_(x, y) << endl;
return ;
}

被遗忘的整数

a*h=(∑ai / n)/(∑(1/ai)),而n*(∑(1/ai))=(∑ai / n),所以n=a*h

#pragma comment(linker, "/STACK:102400000,102400000")
#ifndef ONLINE_JUDGE
#include "stdafx.h"
#else
#include<bits/stdc++.h>
#endif
using namespace std;
typedef long long lint;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef queue<int> QI;
typedef map<int, int> MII; void makedata() {
freopen("input.txt", "w", stdout);
fclose(stdout);
}
int min_(int x, int y) {
if (fabs(x) == fabs(y)) return fabs(x);
return fabs(x) < fabs(y) ? x : y;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//makedata();
std::ios::sync_with_stdio(), cin.tie();
int a, b;
cin >> a >> b;
cout << a*b << endl;
return ;
}

金额组合

#pragma comment(linker, "/STACK:102400000,102400000")
#ifndef ONLINE_JUDGE
#include "stdafx.h"
#else
#include<bits/stdc++.h>
#endif
using namespace std;
typedef long long lint;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef queue<int> QI;
typedef map<int, int> MII; void makedata() {
freopen("input.txt", "w", stdout);
fclose(stdout);
} int n;
lint c;
bool f[];
int s[]; int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//makedata();
std::ios::sync_with_stdio(), cin.tie();
memset(f, false, sizeof(f));
cin >> n >> c;
lint x;
for (int i = ; i < n; i++) {
cin >> x;
for (int j = ; j < ; j++) {
if (x == (1LL << j)) f[j] = true;
}
}
s[] = f[] ? : ;
for (int i = ; i < ; i++) s[i] = s[i - ] + (f[i] ? : );
lint ans = ;
for (int i = ; i >= ; i--) {
if (c & (1LL << i)) {
if (i > ) ans += (1LL << s[i - ]);
else ans += ;
if (!f[i]) break;
}
}
bool ok = true;
for (int i = ; i >= ; i--) {
if (c & (1LL << i) && (!f[i])) ok = false;
}
if (ok) ans++;
ans--;
cout << ans << endl;
return ;
}
/*
1010
----
1000
0100
0001
----
1000
0100
0001
0101
0000
1001
*/

数字组合

#pragma comment(linker, "/STACK:102400000,102400000")
#ifndef ONLINE_JUDGE
#include "stdafx.h"
#else
#include<bits/stdc++.h>
#endif
using namespace std;
typedef long long lint;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef queue<int> QI;
typedef map<int, int> MII; void makedata() {
freopen("input.txt", "w", stdout);
fclose(stdout);
} VI G[];
int cnt[];
int n, k;
int s0, c1;
int max_() {
for (int i = ; i >= ; i--) {
if (cnt[i]) {
cnt[i]--;
n--;
return i;
}
}
}
int min_() {
for (int i = ; i <= ; i++) {
if (cnt[i]) {
cnt[i]--;
n--;
return i;
}
}
}
void work(int l, int r, int p) {
if (p + == s0) return;
int ll;
for (int i = l; i <= r; i++) {
if (G[i][p] < G[r][p]) {
while (G[i].size() < s0) G[i].push_back(max_());
} else {
ll = i;
break;
}
}
for (int i = ll; i <= r; i++) G[i].push_back(min_());
work(ll, r, p + );
} int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//makedata();
std::ios::sync_with_stdio(), cin.tie();
string s;
cin >> n >> k;
cin >> s;
int m = s.length();
for (int i = ; i < m; i++) cnt[s[i] - '']++;
s0 = n / k + , c1 = n % k;
for (int i = ; i < k - c1; i++) G[i].push_back();
for (int i = k - c1; i < k; i++) G[i].push_back(min_());
work(, k - , );
for (int i = ; i < G[k - ].size(); i++) {
if (G[k - ][i] == ) continue;
else cout << G[k - ][i];
}
return ;
}
/*
x 1 1 1 1
44777
*/

[hihocoder][Offer收割]编程练习赛62的更多相关文章

  1. hihocoder [Offer收割]编程练习赛4

    描述 最近天气炎热,小Ho天天宅在家里叫外卖.他常吃的一家餐馆一共有N道菜品,价格分别是A1, A2, ... AN元.并且如果消费总计满X元,还能享受优惠.小Ho是一个不薅羊毛不舒服斯基的人,他希望 ...

  2. hihocoder [Offer收割]编程练习赛61

    [Offer收割]编程练习赛61 A:最小排列 给定一个长度为m的序列b[1..m],再给定一个n,求一个字典序最小的1~n的排列A,使得b是A的子序列. 贪心即可,b是A的子序列,把不在b中的元素, ...

  3. ACM学习历程—Hihocoder [Offer收割]编程练习赛1

    比赛链接:http://hihocoder.com/contest/hihointerview3/problem/1 大概有一个月没怎么打算法了.这一场的前一场BC,也打的不是很好.本来Div1的A和 ...

  4. hihocoder offer收割编程练习赛8 C 数组分拆

    思路:(引自bfsoyc的回答:http://hihocoder.com/discuss/question/4160) 动态规划.状态dp[i]表示 前i个数的合法的方案数,转移是 dp[i] = s ...

  5. hihocoder [Offer收割]编程练习赛18 C 最美和弦(dp)

    题目链接:http://hihocoder.com/problemset/problem/1532 题解:一道基础的dp,设dp[i][j][k][l]表示处理到第几个数,当前是哪个和弦错了几次初始x ...

  6. hihoCoder [Offer收割]编程练习赛3 D子矩阵求和

    子矩阵求和 http://hihocoder.com/discuss/question/3005 声明一下: n是和x一起的,m是和y一起的 x是横着的,y是纵着的,x往右为正,y往下为正 (非常反常 ...

  7. hihocoder [Offer收割]编程练习赛52 D 部门聚会

    看了题目的讨论才会做的 首先一点,算每条边(u, v)对于n*(n+1)/2种[l, r]组合的贡献 正着算不如反着算 哪些[l, r]的组合没有包含这条边(u, v)呢 这个很好算 只需要统计u这半 ...

  8. hihocoder [Offer收割]编程练习赛14

    A.小Hi和小Ho的礼物 谜之第1题,明明是第1题AC率比C还要低.题目是求在n个不同重量袋子选4袋,2袋给A,2袋给B,使2人获得重量相同,求问方案数. 我也是一脸懵b...o(n2)暴力枚举发现把 ...

  9. hihocoder [Offer收割]编程练习赛8

    第一次做这种比赛,被自己坑的好惨... A.这道题的关键其实是如果有k和n满足kD+F>nL>kD则不能走无限远,分支看似难整理,其实比较简单,F>L根本就不用算了,明摆着就是Bsi ...

随机推荐

  1. BNUOJ 1260 Brackets Sequence

    Brackets Sequence Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on PKU. Origi ...

  2. Leetcode 90.子集

    子集 给定一个可能包含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集). 说明:解集不能包含重复的子集. 示例: 输入: [1,2,2] 输出: [ [2], [1], [1,2,2], ...

  3. RSA的共模攻击

    实验吧题目:http://www.shiyanbar.com/ctf/1834 参考:http://hebin.me/2017/09/07/%e8%a5%bf%e6%99%aectf-strength ...

  4. Linux RAR 解压缩

    1.下载 http://www.rarlab.com/download.htm 2.安装 tar zxvf rarlinux-3.8.0.tar.gz cd rar make make install ...

  5. 洛谷—— P2176 [USACO14FEB]路障Roadblock

    https://www.luogu.org/problem/show?pid=2176 题目描述 每天早晨,FJ从家中穿过农场走到牛棚.农场由 N 块农田组成,农田通过 M 条双向道路连接,每条路有一 ...

  6. Spring Cloud ZooKeeper集成Feign的坑2,服务调用了一次后第二次调用就变成了500,错误:Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is com.n

    错误如下: 2017-09-19 15:05:24.659 INFO 9986 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refre ...

  7. Performance Tunning - OCP

    This artical is forcused on Oracle 11g Release 2.  It is an summary from the OCP documentation. The ...

  8. Linux进程空间分布 & 上下文

    Linux使用两级保护机制:0级供内核使用,3级供用户程序使用.从图中可以看出,每个进程有各自的私有用户空间(0~3G),这个空间对系统中的其他进程是不可见的.最高的1GB字节虚拟内核空间则为所有进程 ...

  9. ssh连接断开后 shell进程退出

    问题描述:当SSH远程连接到服务器上,然后运行一个服务 ./catalina.sh start,然后把终端开闭(切断SSH连接)之后,发现该服务中断,导致网页无法访问.   解决方法:使用nohup命 ...

  10. 1.4-动态路由协议OSPF③

    OSPF的路由汇总 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                         用默认的网络地址 因为 无论在何种路 ...