拖了近一个月的总结。(可能源于最近不太想做事:()

A题

给出n个长度都为n的字符串,你只可以对每个字符串分别排序,问当每个字符串按升序排序之后,每一列是否也是升序的。

 #include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std; int main() {
ios::sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
string ch1, ch2;
cin >> ch1;
sort(ch1.begin(), ch1.end());
bool flag = true;
for (int i = ; i < n; i++) {
cin >> ch2;
sort(ch2.begin(), ch2.end());
for (int j = ; j < n; j++) if (ch1[j] > ch2[j]) flag = false;
//if (ch1 > ch2) flag = false;
swap(ch1, ch2);
}
if (flag) cout << "YES\n";
else cout << "NO\n";
} return ;
}

B题

进制转换

 #include <map>
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std; int work(int m, int d) {
int res = , t = ;
while (d) {
if (d % >= m) return -;
res += (d % ) * t;
d /= ;
t *= m;
}
return res;
} int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
map<int, int> mmap;
for (int i = ; i < n; i++) {
int m, d;
cin >> m >> d;
int x = work(m, d);
if (x != -) mmap[x]++;
}
long long res = ;
for (map<int, int>::iterator it = mmap.begin(); it != mmap.end(); it++) res += (long long)(it->second) * (it->second - ) / ;
cout << res << endl;
return ;
}

C题

从N个蜡烛中选出一个子序列使得每种颜色都至少出现一次且序列中蜡烛的高度递增,问存在多少种这样的集合。

因为K较小,那么建立(1<<K)棵梳妆数组,分别维护以hi为最后一根蜡烛的方法数。

 #include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std; const int MAX_N = ;
const int MOD = 1e9 + ;
typedef long long LL;
int H[MAX_N], C[MAX_N], dp[<<];
int c[<<][MAX_N]; int lowbit(int x) {
return x & -x;
} int sum(int id, int x) {
int res = ;
while (x > ) {
res += c[id][x];
if (res >= MOD) res -= MOD;
x -= lowbit(x);
}
return res;
} void add(int id, int x, int v) {
while (x <= MAX_N - ) {
c[id][x] += v;
if (c[id][x] >= MOD) c[id][x] -= MOD;
x += lowbit(x);
}
} int main() {
ios::sync_with_stdio(false);
int N, K;
cin >> N >> K;
for (int i = ; i <= N; i++) {
cin >> H[i] >> C[i];
C[i]--;
} for (int i = ; i <= N; i++) {
for (int j = ; j < (<<K); j++) {
int x = j | (<<C[i]);
dp[j] = sum(j, H[i] - );
//add(x, H[i], s);
}
for (int j = ; j < (<<K); j++) add(j | (<<C[i]), H[i], dp[j]);
add(<<C[i], H[i], );
}
cout << sum((<<K) - , MAX_N - ) << endl; return ;
}

D题

线段树优化DP

 /*************************************************************************
> File Name: Burger_Happiness.cpp
> Author: Stomach_ache
> Mail: sudaweitong@gmail.com
> Created Time: 2014?11?14? ??? 18?12?10?
> Propose: /Hackerrank/Contest/101 Hack October 14
************************************************************************/ #include <cmath>
#include <string>
#include <cstdio>
#include <vector>
#include <fstream>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
/*Let's fight!!!*/ typedef long long LL;
const LL INF = 1LL << ;
const int MOD = 1e9 + ;
const int MAX_N = 1e5 + ;
#define lson(x) (x<<1)
#define rson(x) ((x<<1) | 1)
struct Node {
int l, r;
LL lazy;
LL mmax;
void set(int ll, int rr) {
l = ll;
r = rr;
mmax = ;
lazy = ;
}
}; struct SegmentTree {
Node tr[MAX_N*]; void build(int rt, int l, int r) {
tr[rt].set(l, r);
if (l != r) {
int mid = (l + r) >> ;
build(lson(rt), l, mid);
build(rson(rt), mid + , r);
}
} void pushdown(int rt) {
tr[rt].mmax += tr[rt].lazy;
if (tr[rt].l != tr[rt].r) {
tr[lson(rt)].lazy += tr[rt].lazy;
tr[rson(rt)].lazy += tr[rt].lazy;
}
tr[rt].lazy = ;
} void pushup(int rt) {
tr[rt].mmax = max(tr[lson(rt)].mmax, tr[rson(rt)].mmax);
} // add v to [l, r]
void update(int rt, int l, int r, int v) {
pushdown(rt);
if (r < tr[rt].l || l > tr[rt].r) return ;
if (tr[rt].l >= l && tr[rt].r <= r) {
tr[rt].lazy = v;
pushdown(rt);
} else {
update(lson(rt), l, r, v);
update(rson(rt), l, r, v);
pushup(rt);
}
} // query maximum value in [l, r]
LL query(int rt, int l, int r) {
if (r < tr[rt].l || l > tr[rt].r) return -INF;
pushdown(rt);
if (tr[rt].l >= l && tr[rt].r <= r) {
return tr[rt].mmax;
}
return max(query(lson(rt), l, r), query(rson(rt), l, r));
}
}; SegmentTree T1; // stores maximum f(x) + s[x - 1]
SegmentTree T2; // stores maximum f(x) - s[x] int A[MAX_N], B[MAX_N], X[MAX_N];
LL F[MAX_N];
int main(void) {
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<int> arr;
for (int i = ; i < N; i++) {
cin >> X[i] >> A[i] >> B[i];
arr.push_back(X[i]);
}
sort (arr.begin(), arr.end());
arr.erase(unique(arr.begin(), arr.end()), arr.end());
T1.build(, , N); T2.build(, , N);
for (int i = ; i < N; i++) {
X[i] = lower_bound(arr.begin(), arr.end(), X[i]) - arr.begin() + ;
} LL res = ;
for (int i = ; i < N; i++) {
LL s = -T2.query(, X[i], X[i]); // s[x], since f[x] = 0
LL s1 = T1.query(, X[i], X[i]); // s[x - 1]
// case p < x
LL res1 = -s + A[i] + T1.query(, , X[i]-);
// case p > x
LL res2 = s1 + A[i] + T2.query(, X[i]+, N);
// case beginning from x
LL res3 = A[i];
F[X[i]] = max(max(res1, res2), res3); T1.update(, X[i], X[i], F[X[i]]);
T1.update(, X[i]+, N, B[i]); T2.update(, X[i], X[i], F[X[i]]);
T2.update(, X[i], N, -B[i]); res = max(res, F[X[i]]);
}
cout << res << endl; return ;
}

E题

目前是没有能力做这个题了。

101 Hack October'14的更多相关文章

  1. 101 Hack 50

    101 Hack 50 闲来无事.也静不下心,打个代码压压压惊 Hard Questions by kevinsogo Vincent and Catherine are classmates who ...

  2. Java虚拟机性能管理神器 - VisualVM(4) - JDK版本与VisualVM版本对应关系

    Java虚拟机性能管理神器 - VisualVM(4)    -  JDK版本与VisualVM版本对应关系 JDK版本与VisualVM版本对应关系说明 JDK版本与VisualVM版本对应关系 参 ...

  3. Exercises for IN1900

    Exercises for IN1900October 14, 2019PrefaceThis document contains a number of programming exercises ...

  4. hadoop 2.7.3本地环境运行官方wordcount-基于HDFS

    接上篇<hadoop 2.7.3本地环境运行官方wordcount>.继续在本地模式下测试,本次使用hdfs. 2 本地模式使用fs计数wodcount 上面是直接使用的是linux的文件 ...

  5. Scala HandBook

    目录[-] 1.   Scala有多cool 1.1.     速度! 1.2.     易用的数据结构 1.3.     OOP+FP 1.4.     动态+静态 1.5.     DSL 1.6 ...

  6. 编程:递归编程解决汉诺塔问题(用java实现)

    Answer: //Li Cuiyun,October 14,2016. //用递归方法编程解决汉诺塔问题 package tutorial_3_5; import java.util.*; publ ...

  7. MSI Error 1603 installing AppFabric 1.1 / Win7 x64

    MSI Error 1603 installing AppFabric 1.1 / Win7 x64  Archived Forums A-B > AppFabric Caching   先说解 ...

  8. IE6 7下常见CSS兼容性处理

    以下是一些比较常见的IE6 7下的兼容性问题. 在当下这个时代,其实我们几乎可以不用再去针对IE6做兼容性的处理,除非你的公司还是诡异的要求你兼容到IE6.但是了解一些常见的兼容性问题还是可以帮助我们 ...

  9. mysql集群之MYSQL CLUSTER

    1. 参考文档 http://xuwensong.elastos.org/2014/01/13/ubuntu-%E4%B8%8Bmysql-cluster%E5%AE%89%E8%A3%85%E5%9 ...

随机推荐

  1. golang的时区转换

    一.代码 package main import ( "fmt" "time" ) const TIME_LAYOUT = "2006-01-02 1 ...

  2. SpringBoot_05_ssm拦截器和默认欢迎页面的设置

    1.在springBoot下通过使用拦截器完成在没有登陆的前提下,不允许访问其他资源 编写拦截器,要实现HandlerInterceptor @Component public class UserI ...

  3. P1934 封印

    P1934 封印 题目描述 很久以前,魔界大旱,水井全部干涸,温度也越来越高.为了拯救居民,夜叉族国王龙溟希望能打破神魔之井,进入人界“窃取”水灵珠,以修复大地水脉.可是六界之间皆有封印,神魔之井的封 ...

  4. jmeter-测试https请求

    找了一个HTTPS请求的网站尝试. 我用的是chrome,点这个小锁(如果是IE也可以在网页上右键,属性,高级,证书) 或 看到下图,点击“复制到文件” 或 把导出的证书打成.store 用此命令进行 ...

  5. 18-4-bind

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. 2019-5-15-影子系统让-C++-程序无法运行

    title author date CreateTime categories 影子系统让 C++ 程序无法运行 lindexi 2019-05-15 15:24:35 +0800 2019-05-1 ...

  7. Map和Reduce函数

  8. angular管道操作符的使用

    一.Angular的常用内置管道函数 比如说很多时候我们需要把数字显示成金额.大小写转换.日期小数转换等等. Angular管道对于象这样小型的转换来说是个很方便的选择. 管道是一个简单的函数,它接受 ...

  9. fastjson json转linkedhashmap为null

    试了几种JSONObject.parseObject的方法,返回的都是null: 使用Gson就可以转成功. LinkedHashMap<String, String> map = gso ...

  10. [洛谷P1966] 火柴排队

    题目链接: 火柴排队 题目分析: 感觉比较顺理成章地就能推出来?似乎是个一眼题 交换的话多半会往逆序对上面想,然后题目给那个式子就是拿来吓人的根本没有卵用 唯一的用处大概是告诉你考虑贪心一波,很显然有 ...