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 ...
随机推荐
- 确认某端口占用情况并结束相应进程(Windows)
(1)确认某端口是否被占用 (2)通过查找对应的PID号,定位是哪一个进程在使用该端口 (3)通过PID号结束该进程 # 查找端口2000是否被占用C:\Users\tdcqma>netstat ...
- mapgis处理编辑属性结构时 死机问题
上午用的好好的mapgis6.7,下午就出错了,一编辑属性结构就出错,到网上查到了解决方法,和大家共享一下. 转自:http://bbs.3s001.com/forum.php?mod=viewthr ...
- RMI
Java RMI (Remote Method Invocation 远程方法调用)是用Java在JDK1.1中实现的,它大大增强了Java开发分布式应用的能力.Java作为一种风靡一时的网络开发语言 ...
- [原创]使用命令行工具提升cocos2d-x开发效率(一)之TexturePacker篇
TexturePacker是一个常用的制作sprite sheet的工具,它提供了很多实用的功能. 一般我们制作sprite sheet都是使用他的gui版本,纯手工操作,就像下面这张图示的一样. 刚 ...
- 常用的coco2d-x游戏开发工具(转)
物理编辑工具Physics Editing ToolsMekanimo 网址:http://www.mekanimo.net/PhysicsBench 网址:http://www.cocos2d-ip ...
- [HDOJ3974]Assign the task(建树胡搞)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3974 出现在窝bin的线段树专题里…第一时间想的是记录入度找出根节点,然后标记深度转换到线段树中.但是 ...
- CentOS 6.5系统使用yum方式安装LAMP环境和phpMyAdmin详细过程
介绍如何在CentOs6.2下面使用YUM配置安装LAMP环境,一些兄弟也很喜欢使用编译的安装方法,个人觉得如果不是对服务器做定制,用yum安装稳定简单,何必去download&make&am ...
- tomcat web.xml 配置
1<web-app> 2<error-page> 3<error-code>404</error-code> 4<location>/Not ...
- Reactor模式,或者叫反应器模式
Reactor这个词译成汉语还真没有什么合适的,很多地方叫反应器模式,但更多好像就直接叫reactor模式了,其实我觉着叫应答者模式更好理解一些.通过了解,这个模式更像一个侍卫,一直在等待你的召唤,或 ...
- 使用Quartz创建定时任务
项目开发中经常需要定时循环执行某些任务 比如定时发送报表,定时发送邮件,亦或者定时清理缓存,定时更新数据等等 有些时候可以简单地利用Windows Server的计划任务执行程序 Linux也有相应的 ...