TJOI2013 DAY2
第一题:明显先处理出最终序列,然后用线段树求解。处理最终序列可以用二分加树状数组(时间复杂度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的更多相关文章
- 【从零开始学BPM,Day2】默认表单开发
[课程主题]主题:5天,一起从零开始学习BPM[课程形式]1.为期5天的短任务学习2.每天观看一个视频,视频学习时间自由安排. [第二天课程] Step 1 软件下载:H3 BPM10.0全开放免费下 ...
- BZOJ 3172: [Tjoi2013]单词 [AC自动机 Fail树]
3172: [Tjoi2013]单词 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 3198 Solved: 1532[Submit][Status ...
- NOIp2016 Day1&Day2 解题报告
Day1 T1 toy 本题考查你会不会编程. //toy //by Cydiater //2016.11.19 #include <iostream> #include <cstd ...
- 【BZOJ3172】[Tjoi2013]单词 AC自动机
[BZOJ3172][Tjoi2013]单词 Description 某人读论文,一篇论文是由许多单词组成.但他发现一个单词会在论文中出现很多次,现在想知道每个单词分别在论文中出现多少次. Input ...
- 3172: [Tjoi2013]单词
3172: [Tjoi2013]单词 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 3246 Solved: 1565[Submit][Status ...
- [BZOJ3173][Tjoi2013]最长上升子序列
[BZOJ3173][Tjoi2013]最长上升子序列 试题描述 给定一个序列,初始为空.现在我们将1到N的数字插入到序列中,每次将一个数字插入到一个特定的位置.每插入一个数字,我们都想知道此时最长上 ...
- day2
三级菜单: ))))))))))] last_levels.pop() ]]]]]]]]:] information = : ch = msvcrt.getch() ][][: : password= ...
- java day2一个模拟双色球的代码
package day2; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt ...
- Python基础-day2
1.Python模块python 中导入模块使用import语法格式:import module_name示例1: 导入os模块system('dir')列出当前目录下的所有文件 # _*_ codi ...
随机推荐
- Java API —— 编码 & IO流( InputStreamReader & OutputStreamWriter & FileReader & FileWriter & BufferedReader & BufferedWriter )
1.编码 1)编码表概述 由字符及其对应的数值组成的一张表 2)常见编码表 · ASCII/Unicode 字符集:ASCII是美国标准信息交换码,用一 ...
- apache缓存
http://www.t086.com/article/4256 http://www.360doc.com/content/09/0928/13/41237_6551659.shtml
- sql 随笔 2015-06-30
清除多余字符 --清除多余字符 --' --char(9) 水平制表符 --char(10)换行键 --char(13)回车键 REPLACE( REPLACE( REPLACE(REPLACE([P ...
- 在Ubuntu上为Android增加硬件抽象层(HAL)模块访问Linux内核驱动程序(老罗学习笔记3)
简单来说,硬件驱动程序一方面分布在Linux内核中,另一方面分布在用户空间的硬件抽象层中.接着,在Ubuntu上为Android系统编写Linux内核驱动程序(老罗学习笔记1)一文中举例子说明了如何在 ...
- 转 Android中进入系统设置界面
Android软件时,常常需要打开系统设置或信息界面,来设置相关系统项或查看系统的相关信息,这时我们就可以使用以下语句来实现:(如打开“无线和网络设置”界面) Intent intent = new ...
- UVa 699 The Falling Leaves
题意:给出按先序输入的一颗二叉树,分别求出从左到右的相同横坐标上的节点的权值之和 递归建树,然后用sum数组分别统计每一个横坐标上的权值之和 感觉建树都在递归递归递归= =慢慢理解吧 #include ...
- SVN备份及其还原 — dump/load方法
本文中采用最简单的dump/load方法.备份:一个较大的Subsersion版本库想用最少的空间来将它备份下来,用这个命令(请将/repo替换成你的版本库路径)svnadmin dump --del ...
- IIS没有ASP.NET选项卡
问题: 1.IIS没有ASP.NET选项卡 2.默认文档不起作用 分析: 1,在安装了.net framework 2.0后,iis站点属性里才会有asp.net的选项. 2,安装asp.net2.0 ...
- 转:ASP.NET MVC中Unobtrusive Ajax的妙用
Unobtrusive Javascript有三层含义:一是在HTML代码中不会随意的插入Javsscript代码,只在标签中加一些额外的属性值,然后被引用的脚本文件识别和处理:二是通过脚本文件所增加 ...
- (转)在mac上配置cocos2d-x开发环境
转自:http://www.cnblogs.com/xiaodao/archive/2013/01/08/2850751.html 一.下载cocos2d-x最新安装包 在终端中cd到本地将要存放目录 ...