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

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. 最大流拆点——hdu2732,poj3436

    一种很普遍的做法就是把一个带有容量的点拆成两个点,一个入点一个出点,链接两个点的边的权值为这个点的容量 hdu3732 #include<cstdio> #include<cstri ...

  2. iOS开发之SceneKit框架--SCNAction.h

    1.SCNAction简介 主要负责节点SCNNode的属性,实现node的渐变.移动.出现.消失.实现动画等. 2.相关API 节点的移动(earthNode的初始坐标(5,0,0)) //从当前位 ...

  3. quartz的job中注入spring对象!

    一般情况下,quartz的job中使用autowired注解注入的对象为空,这时候我们就要使用spring-quartz提供的AdaptableJobFactory类. 自定义一个类: public  ...

  4. qfc 问题汇总(TO BE CONTINUED)

    硬件问题 增加一个复位按钮 程序问题 /* uart allocation: PB6-7: UART1 -> TELEM PD5-6 : UART2 -> SBUS PD8-9: UART ...

  5. CSS 实现自适应正方形

    在处理移动端页面时,我们有时会需要将banner图做成与屏幕等宽的正方形以获得最佳的体验效果,比如,商品详情页, 方法1.CSS3 vw单位 CSS3 中新增了一组相对于可视区域百分比的长度单位 vw ...

  6. 03_mybatis配置文件详解

    1. SqlMapConfig.xml mybatis全局配置文件SqlMapConfig.xml,配置内容如下: *properties(属性) setting(全局配置参数) typeAliase ...

  7. Android开发 EditText按回车按键后出现 focus search returned a view that wasn't able to take focus! 错误

    问题描述 将EditText这个View成为了ListView或者RecyclerView的item时,在按输入法的回车/下一步/next时会出现的 focus search returned a v ...

  8. datetime与timestamp相互转换

    select unix_timestamp('2019-12-05 12:26:35'); );

  9. 在vc2008 mfcC++中使用sqlite的示例

    http://owlman.org/?p=890 在C++中使用sqlite的示例 2011年8月5日admin发表评论阅读评论 最近因为工作原因,终于使我有机会腾出时间来接触了一下SQLite数据库 ...

  10. LUOGU P4027 [NOI2007]货币兑换 (斜率优化+CDQ分治)

    传送门 解题思路 题目里有两句提示一定要看清楚,要不全买要不全卖,所以dp方程就比较好列,f[i]=max(f[j]*rate[j]*a[i])/(rate[j]*a[j]+b[j])+(f[j]*b ...