第一题:明显先处理出最终序列,然后用线段树求解。处理最终序列可以用二分加树状数组(时间复杂度log2n, 用平衡树也可以搞。。。)。

/*
* Problem: TJOI2013-day2-Sequence
* Author: Shun Yao
*/ #include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <assert.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <time.h> #include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <vector>
#include <bitset>
#include <utility>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> //using namespace std; const int MAXN = 100010; int getInt() {
static char ch, f;
static int ret;
f = 1;
while (ch = getchar(), ch < '0' || ch > '9')
if (ch == '-')
f = 0;
ret = ch - '0';
while (ch = getchar(), ch >= '0' && ch <= '9')
ret = (ret << 1) + (ret << 3) + ch - '0';
return f ? ret : -ret;
} int n; int s[MAXN];
void modify(int x, int y) {
static int i;
for (i = x; i <= n; i += i & -i)
s[i] += y;
}
int query(int x) {
static int i, ret;
ret = 0;
for (i = x; i >= 1; i -= i & -i)
ret += s[i];
return ret;
} struct SegTree {
int v;
SegTree *l, *r;
} *root;
void build(SegTree *&p, int l, int r) {
p = new SegTree();
p->v = 0;
p->l = p->r = NULL;
if (l == r)
return;
build(p->l, l, (l + r) >> 1);
build(p->r, ((l + r) >> 1) + 1, r);
}
void modify(SegTree *p, int l, int r, int x, int y) {
if (l == r) {
p->v = y;
return;
}
if (x <= (l + r) >> 1)
modify(p->l, l, (l + r) >> 1, x, y);
else
modify(p->r, ((l + r) >> 1) + 1, r, x, y);
p->v = std::max(p->l->v, p->r->v);
}
int query(SegTree *p, int l, int r, int x, int y) {
if (l == x && y == r)
return p->v;
if (y <= (l + r) >> 1)
return query(p->l, l, (l + r) >> 1, x, y);
else if (x > (l + r) >> 1)
return query(p->r, ((l + r) >> 1) + 1, r, x, y);
return std::max(query(p->l, l, (l + r) >> 1, x, (l + r) >> 1), query(p->r, ((l + r) >> 1) + 1, r, ((l + r) >> 1) + 1, y));
} int main(/*int argc, char **argv*/) {
int i, j, mid, l, r, x[MAXN], a[MAXN], ans;
char v[MAXN]; freopen("sequence.in", "r", stdin);
freopen("sequence.out", "w", stdout); n = getInt();
for (i = 1; i <= n; ++i)
x[i] = getInt();
memset(v, 0, sizeof v);
for (i = n; i >= 1; --i) {
l = 1;
r = n;
while (l <= r) {
mid = (l + r) >> 1;
j = mid - query(mid);
if (j == x[i] + 1) {
if (!v[mid]) {
v[a[i] = mid] = 1;
modify(mid, 1);
break;
} else
r = mid - 1;
continue;
}
if (j > x[i] + 1)
r = mid - 1;
else
l = mid + 1;
}
}
build(root, 1, n);
ans = 0;
for (i = 1; i <= n; ++i) {
j = query(root, 1, n, 1, a[i]);
modify(root, 1, n, a[i], j + 1);
if (ans < j + 1)
ans = j + 1;
printf("%d\n", ans);
} fclose(stdin);
fclose(stdout);
return 0;
}

第二题:仔细分析可以发现应该按照a + b递增的顺序贪心出井,然后dp,f[i][j]代表前i个逃离了j个的剩余最大高度。

/*
* Problem: Dwarf
* Author: Shun Yao
*/ #include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <assert.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <time.h> #include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <vector>
#include <bitset>
#include <utility>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> //using namespace std; const int MAXN = 2222; int n, f[MAXN]; struct Data {
int a, b;
} c[MAXN]; bool cmpa(Data a, Data b) {
return a.a + a.b < b.a + b.b;
} int main(/*int argc, char **argv*/) {
int i, j, h; freopen("dwarf.in", "r", stdin);
freopen("dwarf.out", "w", stdout); scanf("%d", &n);
for (i = 1; i <= n; ++i)
scanf("%d%d", &c[i].a, &c[i].b);
scanf("%d", &h);
std::sort(c + 1, c + n + 1, cmpa);
for (i = 1; i <= n; ++i)
f[0] += c[i].a;
for (i = 1; i <= n; ++i)
f[i] = INT_MIN;
for (i = 1; i <= n; ++i)
for (j = i; j >= 1; --j)
if (f[j - 1] != INT_MIN && f[j - 1] + c[i].b >= h && f[j] < f[j - 1] - c[i].a)
f[j] = f[j - 1] - c[i].a;
for (i = n; i >= 0; --i)
if (f[i] >= 0)
break;
printf("%d", i); fclose(stdin);
fclose(stdout);
return 0;
}

第三题:好吧,很明显二分图独立集(好像是好经典的题目啊!,据说匈牙利会被卡爆,我在BZOJ上交的。。。)

/*
* Problem: TJOI2013-day2-Attack
* Author: Shun Yao
*/ #include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <assert.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <time.h> #include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <vector>
#include <bitset>
#include <utility>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> //using namespace std; const int MAXN = 222;
const int dx[8] = {1, 1, -1, -1, 2, 2, -2, -2};
const int dy[8] = {2, -2, 2, -2, 1, -1, 1, -1}; int n, mat[MAXN * MAXN];
bool used[MAXN * MAXN]; class Edge {
public:
int v;
Edge *next;
Edge() {}
~Edge() {}
Edge(int V, Edge *ne) : v(V), next(ne) {}
} *g[MAXN * MAXN]; void add(int x, int y) {
g[x] = new Edge(y, g[x]);
} bool find(int x) {
for (Edge *e = g[x]; e; e = e->next)
if (!used[e->v]) {
used[e->v] = 1;
if (!mat[e->v] || find(mat[e->v])) {
mat[e->v] = x;
return 1;
}
}
return 0;
} int main(/*int argc, char **argv*/) {
int i, j, k, x, y, ans, sum;
char s[MAXN][MAXN]; freopen("attack.in", "r", stdin);
freopen("attack.out", "w", stdout); scanf("%d", &n);
for (i = 1; i <= n; ++i)
scanf(" %s", s[i] + 1);
sum = 0;
for (i = 1; i <= n; ++i)
for (j = 1; j <= n; ++j) {
if (s[i][j] == '1')
continue;
++sum;
if ((i + j) & 1)
for (k = 0; k < 8; ++k) {
x = i + dx[k];
y = j + dy[k];
if (x < 1 || x > n || y < 1 || y > n || s[x][y] == '1')
continue;
add((i - 1) * n + j, (x - 1) * n + y);
}
}
ans = 0;
memset(mat, 0, sizeof mat);
for (i = 1; i <= n; ++i)
for (j = 1; j <= n; ++j)
if (s[i][j] == '0' && (i + j) & 1) {
memset(used, 0, sizeof used);
if (find((i - 1) * n + j))
++ans;
}
printf("%d\n", sum - ans); fclose(stdin);
fclose(stdout);
return 0;
}

TJOI2013 DAY2的更多相关文章

  1. 【从零开始学BPM,Day2】默认表单开发

    [课程主题]主题:5天,一起从零开始学习BPM[课程形式]1.为期5天的短任务学习2.每天观看一个视频,视频学习时间自由安排. [第二天课程] Step 1 软件下载:H3 BPM10.0全开放免费下 ...

  2. BZOJ 3172: [Tjoi2013]单词 [AC自动机 Fail树]

    3172: [Tjoi2013]单词 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 3198  Solved: 1532[Submit][Status ...

  3. NOIp2016 Day1&Day2 解题报告

    Day1 T1 toy 本题考查你会不会编程. //toy //by Cydiater //2016.11.19 #include <iostream> #include <cstd ...

  4. 【BZOJ3172】[Tjoi2013]单词 AC自动机

    [BZOJ3172][Tjoi2013]单词 Description 某人读论文,一篇论文是由许多单词组成.但他发现一个单词会在论文中出现很多次,现在想知道每个单词分别在论文中出现多少次. Input ...

  5. 3172: [Tjoi2013]单词

    3172: [Tjoi2013]单词 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 3246  Solved: 1565[Submit][Status ...

  6. [BZOJ3173][Tjoi2013]最长上升子序列

    [BZOJ3173][Tjoi2013]最长上升子序列 试题描述 给定一个序列,初始为空.现在我们将1到N的数字插入到序列中,每次将一个数字插入到一个特定的位置.每插入一个数字,我们都想知道此时最长上 ...

  7. day2

    三级菜单: ))))))))))] last_levels.pop() ]]]]]]]]:] information = : ch = msvcrt.getch() ][][: : password= ...

  8. java day2一个模拟双色球的代码

    package day2; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt ...

  9. Python基础-day2

    1.Python模块python 中导入模块使用import语法格式:import module_name示例1: 导入os模块system('dir')列出当前目录下的所有文件 # _*_ codi ...

随机推荐

  1. CMake with Win&MinGW

    今天一个下午都在做一件简直耻辱play的事情,论文没看,程序没写,玩了一个下午的编译器...心塞(逃... 言归正传,今天要讲在windows下,使用Cmake和MInGW. 1.g++ MinGW的 ...

  2. Tomcat的SessionID引起的Session Fixation和Session Hijacking问题

    上一篇说到<Spring MVC防御CSRF.XSS和SQL注入攻击>,今天说说SessionID带来的漏洞攻击问题.首先,什么是Session Fixation攻击和Session Hi ...

  3. 关于Javascript函数的几点笔记

    函数本质上是一个有名字的程序块,程序块使得多条语句可以一起执行. 变量类型: 1.复杂类型:Object.Array等. 2.原始类型:String.Integer等. 函数参数: 1.复杂类型:传递 ...

  4. 非常实用的PHP代码片段推荐

    当使用PHP进行开发的时候,如果你自己收 藏 了一些非常有用的方法或者代码片段,那么将会给你的开发工作带来极大的便利.今天我们将介绍10个超级好用的PHP代码片段,希望大家能够喜欢! 1.  使用te ...

  5. PHP5.4连接sqlserver

    1.下载微软的php连接驱动:SQLSRV30.EXE(5.4对应,后面的native client要用2012)/SQLSRV20.EXE(5.3对应,native client要用2008)/SQ ...

  6. Hibernate--基本映射标签和属性介绍

    一.映射文件的基本结构举例: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hiberna ...

  7. POJ 2065 SETI(高斯消元)

    题目链接:http://poj.org/problem?id=2065 题意:给出一个字符串S[1,n],字母a-z代表1到26,*代表0.我们用数组C[i]表示S[i]经过该变换得到的数字.给出一个 ...

  8. bash shell 合并文件

    # 按列合并文件 paste file1 file2 file3 > file4 # 要先 sort, 再 file1 file2 paste格式为: paste -d -s -file1 fi ...

  9. iOS开发:插件记录

    进入沙盒的插件 https://github.com/TongeJie/ZLGotoSandboxPlugin 图片提示的插件 https://github.com/ksuther/KSImageNa ...

  10. jquery dialog-优雅的弹出框

    前面一章已经对datepicker的使用,做了简单的说明.这一章主要对dialog如何使用做个说明.         jquery ui-dialog在web开发中运用还是比较多的.最常见的例子就是登 ...