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

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. Delphi 查找标题已知的窗口句柄,遍历窗口控件句柄

    有了回调函数的概念及上面的例子,我们可以继续了.其实想要找到一个标题已知的窗口句柄,用一个API函数就可以了:FindWindow.其函数原形是:function FindWindow(lpClass ...

  2. springboot下自定义配置文件,并在项目里读取的方法

    首先 pom文件引入springboot文件处理器 <dependency> <groupId>org.springframework.boot</groupId> ...

  3. 02-Nov-2017 07:11:56.475 信息 [http-nio-8080-exec-10] com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource. Initializing c3p0 pool...

    报错: 02-Nov-2017 07:11:56.475 信息 [http-nio-8080-exec-10] com.mchange.v2.c3p0.impl.AbstractPoolBackedD ...

  4. clover无缘无故隐藏书签栏原因

    可能是不小心按住了Ctrl+shift+B

  5. day22_6-re模块

    # 参考资料:# python模块(转自Yuan先生) - 狂奔__蜗牛 - 博客园# https://www.cnblogs.com/guojintao/articles/9070485.html ...

  6. openstack各组件介绍

    Nova:计算服务,通过虚拟化技术,实现虚拟机的创建,管理,删除,是openstack中最核心的服务. Neutron:网络服务,为虚拟机提供网络连接服务,就像物理机的交换机和路由器一样 Glance ...

  7. KVM桥接网络

    1.什么是桥接网络 桥接网络:是指直接连接物理网络 桥接与NAT的区别:NAT是通过共享主机ip的方式进行上网,在你本地局域网内,别人是无法看到的:而桥接网络,是虚拟机通过dhcp的方式获取一个ip地 ...

  8. Print Article /// 斜率优化DP oj26302

    题目大意: 经典题 数学分析 G(a,b)<sum[i]时 a优于b G(a,b)<G(b,c)<sum[i]时 b必不为最优 #include <bits/stdc++.h& ...

  9. web系统基础

    网络标准体系架构 B/S(browser/server浏览器)服务器有iis.apache.Tomcat.Ngix.Lighttp等 C/S(client/server客户端)如微信.QQ.Outlo ...

  10. SpringMVC的Hello World

    本次使用Maven和Spring IO platform创建SpringMVC的Hello World. 一.Maven的Pom文件内容如下: <project xmlns="http ...