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 ...
随机推荐
- linux 免交互状态下修改用户密码
当利用某些工具对linux用户进行远程密码更改时,输入[ passwd 用户名 ] 后需要输入两次密码, 但是如果你利用的某些工具无法与linux进行交互的情况下,就没办法变更用户密码了,这个时候可以 ...
- EINTR错误
慢系统调用(slow system call):此术语适用于那些可能永远阻塞的系统调用.永远阻塞的系统调用是指调用有可能永远无法返回,多数网络支持函数都属于这一类.如:若没有客户连接到服务器上,那么服 ...
- 【转载】git/github初级运用自如
之前了解过github,并在上面看了一些项目的源代码,于是自己也在github上创建了账户,希望以后有机会也把自己的项目托管在上面去.但是前提你要先了解git/github,下面的内容是从我的好基友虫 ...
- 简单的算法题, Find Minimum in Rotated Sorted Array 的Python实现。
简单的算法题, Find Minimum in Rotated Sorted Array 的Python实现. 题目: Suppose a sorted array is rotated at som ...
- JodaTime初体验
前段时间用JDK自带的Calendar类来处理日期,需要获取年.季,月,星期的起始日期,被折腾得要死要活.看了这篇文章 http://www.blogbus.com/dreamhead-logs/22 ...
- Github欢乐多 PHP神级代码引发吐槽热
前日,github的PHP板块惊现一段能够提升70%运行效率的代码,引发了全世界众多网友的吐槽和调侃,“awesome!”.“well done!”.“PHP是世界第一语言!”平时不苟言笑,埋头苦干的 ...
- ios 使用GCD 多线程 教程
什么是GCD Grand Central Dispatch (GCD)是Apple开发的一个多核编程的解决方法.该方法在Mac OS X 10.6雪豹中首次推出,并随后被引入到了iOS4.0中.GCD ...
- The type xxx cannot be resolved. It is indirectly referenced from required .class files
项目A中引入一个jar包B,在项目A中调用项目B,出现如下错误提示: 大致意思是:这上面所需的包是间接引用的,即A项目调用B项目,B项目又引用了另外一个包C,而这个包现在不在你的A项目的引用中. ...
- jenkins 状态管理
如何安装Jenkins as rpm: $ sudo service jenkins restart Usage: /etc/init.d/jenkins {start|stop|status|res ...
- hdu 4952 Number Transformation (找规律)
题目链接 题意:给你个x,k次操作,对于第i次操作是:要找个nx,使得nx是>=x的最小值,且能整除i,求k次操作后的数 分析: 经过打表找规律,会发现最后的x/i,这个倍数会趋于一个固定的值, ...