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

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. hibernate_01_SSH环境搭建

    1.maven工程pom.xml文件 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="h ...

  2. 牛客多校第五场 G subsequence 1 最长公共子序列/组合数

    题意: 给定两个由数字组成的序列s,t,找出s所有数值大于t的子序列.注意不是字典序大. 题解: 首先特判s比t短或一样长的情况. 当s比t长时,直接用组合数计算s不以0开头的,长度大于t的所有子序列 ...

  3. c++中变量、变量名、变量地址、指针、引用等含义

    首先了解内存,内存就是一排房间,编号从0开始,0,1,2,3,4,5...... 房间里面一定要住人,新人住进去了,原来的人就走了:不管你住不住,里面都有人. 编号就是地址.里面的人就是内容,为了我们 ...

  4. python的__file__和__name__变量

    #现在的目录结构为 #现在想要在web2/bin.py中调用web3/main.py模块中的方法 from web3 import main main.foo() #在pycharm中执行 ##### ...

  5. 旋转矩形碰撞检测 OBB方向包围盒算法

    在cocos2dx中进行矩形的碰撞检测时需要对旋转过的矩形做碰撞检查,由于游戏没有使用Box2D等物理引擎,所以采用了OBB(Oriented bounding box)方向包围盒算法,这个算法是基于 ...

  6. 7款外观迷人的HTML5/CSS3 3D特效按钮特效

    下面我整理了7款外观都十分迷人的HTML5/CSS3 3D按钮特效,有几个还挺实用的,分享给大家. 1.CSS3超酷3D弹性按钮 按钮实现非常简单 之前我们分享过几款不错的CSS3 3D立体按钮,比如 ...

  7. ListControl 设置表格行高与字体

    设置行高: CImageList   m_l;  m_l.Create(1,18,TRUE|ILC_COLOR32,1,0);   listCtrl.SetImageList(&m_l,LVS ...

  8. apache tomcat 一个网站多域名的实现方法

    因此处是进行多域名设置,所以 Apache 与 tomcat的结合没有详述,此处只是设置多域名的方法 windows下 C:\WINDOWS\system32\drivers\etc 文件夹内 hos ...

  9. table方法也属于模型类的连贯操作方法之一

    table方法也属于模型类的连贯操作方法之一,主要用于指定操作的数据表. 用法 一般情况下,操作模型的时候系统能够自动识别当前对应的数据表,所以,使用table方法的情况通常是为了: 切换操作的数据表 ...

  10. Django 操作Cookie与Session

    目录 Cookie Session Django中操作Cookie 基本操作 基于cookie的登录装饰器 Django中操作Session 基本操作 Session流程解析 基于session的登录 ...