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

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. spring mvc多环境下配置文件的设置

    在实际开发时经常需要把一些配置信息写在配置文件,比如mysql的主机地址.端口号.用户名和密码等.另外,在开发代码时可能用一套配置参数,而部署到测试环境时又会用另一套配置参数,测试完毕再部署到线上环境 ...

  2. Seam科普

    声明:这是引用的,具体引用位置在最下面. 只供个人学习,免得忘记了又要到处找,十分感谢原作作者.如果有什么问题请联系我. Seam框架开发一个HelloWrld的例子. Seam本身,而在于Seam使 ...

  3. Foundation框架系列-NSDictionary

    排序 对字典中的key按照字母升序排序 // NOTE: 排序,得出最终请求字串 NSArray* sortedKeyArray = [[tmpDict allKeys] sortedArrayUsi ...

  4. iOS开发系列-JSON解析

    概述 JOSN是一种轻量级的数据格式,一般用于数据交互.服务器返回给客户端,一般都是JSON格式或者XML格式. JSON的格式: {"name" : "CoderHon ...

  5. OpenGL 鼠标交互响应事件

    OpenGL 鼠标.键盘交互响应事件 先来一个样例: uses gl,glu,glut; procedure InitEnvironment;cdecl; begin glClearColor();/ ...

  6. Python全栈开发:Mysql(一)

    一.概述 1.什么是数据库 ? 答:数据的仓库,如:在ATM的示例中我们创建了一个 db 目录,称其为数据库 2.什么是 MySQL.Oracle.SQLite.Access.MS SQL Serve ...

  7. mysql主从复制linux配置(二进制日志文件)

    安装mysql,两台机器一主(192.168.131.153),一从(192.168.131.154) 主机配置 修改主/etc/my.cnf文件 添加 #server_id=153 ###服务器id ...

  8. 使用openSUSE Leap 42.2小记

    闪存记录 在2017年04月10日开始想用openSuSE. 2017年04月10日开始找资料制作U盘安装openSUSE. 是在windows 7中用imageWrite.exe 软件制作的.安装的 ...

  9. 2016.9.15初中部上午NOIP普及组比赛总结

    2016.9.15初中部上午NOIP普及组比赛总结 2016.09.15[初中部 NOIP普及组 ]模拟赛 又翻车了!表示时超和空超很可恨! 进度 比赛:AC+0+0+20=120 改题:AC+80+ ...

  10. RMQ问题——ST算法

    比赛当中,常会出现RMQ问题,即求区间最大(小)值.我们该怎样解决呢? 主要方法有线段树.ST.树状数组.splay. 例题 题目描述 2008年9月25日21点10分,酒泉卫星发射中心指控大厅里,随 ...