#####Time 7:50 AM -> 11:15 AM
感觉今天考完后,我的内心是崩溃的


试题

考试包


T1:

首先看起来是个贪心,然而,然而,看到那个100%数据为n <= 2000整个人就虚了,发呆接近两小时后意识到这个应该是个dp,然后开始考虑dp方程,脑残把dp打成了n^3,果断上天。。而且在转移过程中推错多打了一个-1,于是3个wa 1个ac 6个TLE ,10分滚粗

T1 dp 正解:

使用二维dp记录当前状态,dp[i][j]表示在前i个妖精中选择了j个妖精的最小时间,转移过程如下:

1、

如果dp[i-1][j] != inf dp[i][j] = min(dp[i][j], dp[i-1][j]);

2、

如果dp[i-1][j-1] != inf 即可以转移,如果dp[i-1][j-1] < l[i] 那么dp[i][j] = min(dp[i][j], l[i] + t[i] -1),否则dp[i][j] = min(dp[i][j], dp[i-1][j-1] + t[i]);最后逆序枚举dp[n][i]输出第一个小于inf的i值即为答案

#include <cstdio>
#include <cstring>
#include <algorithm> const int maxn = 2000 + 100; int dp[maxn][maxn];
int li[maxn], ri[maxn], ti[maxn];
int n; int main () {
freopen("sanae.in", "r", stdin);
freopen("sanae.out", "w", stdout);
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d %d %d", &li[i], &ri[i], &ti[i]);
memset(dp, 127, sizeof(dp));
for (int i = 0; i <= n; i++) dp[i][0] = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= i; j++) {
if (dp[i-1][j] != 0x3f3f3f3f) {
dp[i][j] = std :: min(dp[i][j], dp[i-1][j]);
}
if (dp[i-1][j-1] != 0x3f3f3f3f) {
if (dp[i-1][j-1] < li[i]) dp[i][j] = std :: min(li[i] + ti[i] - 1, dp[i][j]);
else {
int cend = dp[i-1][j-1] + ti[i];
if (cend <= ri[i]) {
dp[i][j] = std :: min(dp[i][j], cend);
}
}
}
}
for (int i = n; i >= 0; i--)
if (dp[n][i] < 0x3f3f3f3f) {
printf("%d", i);
break;
}
return 0;
} /*
7
3 12 6
7 13 6
9 14 3
13 22 7
13 24 5
16 24 3
16 26 6
*/

T3

历经一下午思考以及apt123大神讲解,终于算是A了这道world final的B题。考试时看到数据范围,果断的写了dfs,30分到手,也算是勉强弥补了一下第一题的坑

先来粘一下作者给的无比详细(shi fen jian lue)的题解

我们将所有给出的三元环看做点,把所有边也看成点。把三元环所对应的点与组成这个三元环的边所对应的点连线,这样我们就得到了一棵树。问题转化为:在这棵树上取一棵有最多叶子结点的子树,满足:

1、 代表原三元环的点的所有连出的边都可以选。

2、 代表原边的点只能选两条连出的边。

树形dp即可。

呵呵



再来看一下gcj给的题解

This proved to be the easiest problem in the finals for the experienced competitors.

We get some insight into the problem by noticing the graph resembles a tree. These graphs are actually called partial 2-trees. We can actually build a tree if we follow the way the graph is constructed. We build another graph that associates a node to each new added cycle of length this cycle shares an edge to an old cycle so we add an edge between the two respective nodes in the second graph. This way we have built the tree decomposition of these graphs. As on trees many problems that are hard to solve on general graphs have polynomial algorithms on this type of graphs.

Let's solve the related problem of finding the longest path in a tree. We can use dynamic programming and depth first search. We mark a node as a root. Every path in the tree has exactly one node that is closest to the root and this node splits the path in two downward paths. Now for each node in the tree we compute the longest downwards path that starts in it. To find the largest path in the tree we look at each node and at the two longest paths that start in it's children. This solves the problem in linear time.

The solution for our original problem is pretty similar. For each edge (x,y), we compute the cycle that contains it and and all the other nodes in the cycle have larger indexes. Let's call this a downward cycle since it goes the opposite direction of where the initial three nodes are. To find that number we have to look at all higher indexed nodes that were connected to this edge and try to use them as intermediary points in the cycle. So for a given intermediary point z we can build a cycle by looking at the longest downward cycle that contains the edge (x,z) and the longest downward cycle that contains the edge (z,y), use all the edges, add edge (x,y) and remove the edges (x,z) and (z,y).

We also compute the largest downward cycle which contains these two nodes but doesn't contain this edge, this is a union of the cycle that goes through these nodes and the second largest path from which we remove the edge (x,y).

呵呵

好吧我们开始自食其力

T3题解 以及 我对T3的理解:

很显然这张图不是一般的图(废话),我们不难发现这张图实际上是由若干个小三角形组成的(即题解中所说的三元组),那么对于



这种形状的图来说,我们只能从中选取两个三角形来进行操作,从而推知,对于任意一条边,最多只有两个与之相连三角形被选取,因此,可以选择从四周向中间的123转移

设a数组记录了每个点连出去的两个点,用每个后加入点的标号表示三角形的标号,b数组代表从其余两个方向递推过来时的最大值,



即图中的7 -> 5 和 6 -> 5,c数组表示通过1、2、3边的最大值,为保证转移正确在读入时直接保证a[i][0] < a[i][1],之后每一步根据转移目标是否为123的三角形进行分情况讨论并转移,注意每一步需要尝试更新ans值, ans值并不一定会在123三角形中取得。注意转移细节,详见代码

#include <cstdio>
#include <algorithm>
#include <cstring> const int maxn = 100000 + 100;
int a[maxn][2];
int b[maxn][2];
int c[100][100];
int n;
int ans = 0; int main () {
freopen("aya.in", "r", stdin);
freopen("aya.out", "w", stdout);
scanf("%d", &n);
for (int i = 4; i <= n; i++) {
scanf("%d %d", &a[i][0], &a[i][1]);
if (a[i][0] > a[i][1]) {
int t = a[i][0];
a[i][0] = a[i][1];
a[i][1] = t;
}
}
for (int i = n; i >= 4; i--) {
if (a[i][1] < 4) {
ans = std :: max(ans, c[a[i][0]][a[i][1]] + b[i][1] + b[i][0] + 3);
c[a[i][0]][a[i][1]] = std :: max(c[a[i][0]][a[i][1]], b[i][1] + b[i][0] + 1);
} else {
if (a[a[i][1]][0] == a[i][0]) {
ans = std :: max(ans, b[a[i][1]][0] + b[i][0] + b[i][1] + 3);
b[a[i][1]][0] = std :: max(b[a[i][1]][0], b[i][0] + b[i][1] + 1);
} else {
ans = std :: max(ans, b[a[i][1]][1] + b[i][1] + b[i][0] + 3);
b[a[i][1]][1] = std :: max(b[a[i][1]][1], b[i][0] + b[i][1] + 1);
}
}
}
ans = std :: max(ans, c[1][2] + c[2][3] + c[1][3] + 3);
printf("%d", ans);
return 0;
}

以及R神的pascal代码

var
n,i,j,ans:longint;
a,b:array[1..100000,1..2]of longint;
bb:array[1..3,1..3]of longint;
function max(a,b:longint):longint;
begin
if a>b then exit(a);exit(b);
end;
begin
assign(input,'aya.in');
reset(input);
assign(output,'aya.out');
rewrite(output);
readln(n);
for i:=4 to n do
begin
readln(a[i,1],a[i,2]);
if a[i,1]>a[i,2] then
begin
j:=a[i,1];
a[i,1]:=a[i,2];
a[i,2]:=j;
end;
end;
for i:=n downto 4 do
begin
if a[i,2]<4 then
begin
ans:=max(ans,bb[a[i,1],a[i,2]]+b[i,1]+b[i,2]+3);
bb[a[i,1],a[i,2]]:=max(bb[a[i,1],a[i,2]],b[i,1]+b[i,2]+1);
end
else
begin
if a[a[i,2],1]=a[i,1] then
begin
ans:=max(ans,b[a[i,2],1]+b[i,1]+b[i,2]+3);
b[a[i,2],1]:=max(b[a[i,2],1],b[i,1]+b[i,2]+1);
end
else
begin
ans:=max(ans,b[a[i,2],2]+b[i,1]+b[i,2]+3);
b[a[i,2],2]:=max(b[a[i,2],2],b[i,1]+b[i,2]+1);
end;
end;
end;
ans:=max(ans,bb[1,2]+bb[1,3]+bb[2,3]+3);
writeln(ans);
close(input);
close(output);
end.



2016 10 26考试 NOIP模拟赛 杂题的更多相关文章

  1. 【2018.10.20】noip模拟赛Day3 飞行时间

    今天模拟赛题目 纯考输入的傻逼题,用$scanf$用到思想僵化的我最终成功被$if$大法爆$0$了(这题只有一组$100$分数据). 输入后面那个$(+1/2)$很难$if$判断,所以我们要判两个字符 ...

  2. noip模拟赛 水题

    题目描述 LYK出了道水题. 这个水题是这样的:有两副牌,每副牌都有n张. 对于第一副牌的每张牌长和宽分别是xi和yi.对于第二副牌的每张牌长和宽分别是aj和bj.第一副牌的第i张牌能覆盖第二副牌的第 ...

  3. 2016.11.6 night NOIP模拟赛 考试整理

    题目+数据:链接:http://pan.baidu.com/s/1hssN8GG 密码:bjw8总结: 总分:300分,仅仅拿了120份. 这次所犯的失误:对于2,3题目,我刚刚看就想到了正确思路,急 ...

  4. 【2018.10.18】noip模拟赛Day2 地球危机(2018年第九届蓝桥杯C/C++A组省赛 三体攻击)

    题目描述 三体人将对地球发起攻击.为了抵御攻击,地球人派出了 $A × B × C$ 艘战舰,在太 空中排成一个 $A$ 层 $B$ 行 $C$ 列的立方体.其中,第 $i$ 层第 $j$ 行第 $k ...

  5. 【2018.10.20】noip模拟赛Day3 二阶和

    今年BJ省选某题的弱化版…… 这看起来就没那么难了,有几种方法维护,这里提两种. 第一种(傻逼的我写的) 维护 一维&二维前缀和. 对于一个长度为$m$的序列$b_1,b_2,...,b_m$ ...

  6. 【2018.10.15】noip模拟赛Day1

    题面 wzj的题解 T1 随便搜 #include<bits/stdc++.h> #define ll long long using namespace std; inline int ...

  7. 10.17 NOIP模拟赛

    目录 2018.10.17 NOIP模拟赛 A 咒语curse B 神光light(二分 DP) C 迷宫maze(次短路) 考试代码 B 2018.10.17 NOIP模拟赛 时间:1h15min( ...

  8. 10.16 NOIP模拟赛

    目录 2018.10.16 NOIP模拟赛 A 购物shop B 期望exp(DP 期望 按位计算) C 魔法迷宫maze(状压 暴力) 考试代码 C 2018.10.16 NOIP模拟赛 时间:2h ...

  9. NOIP模拟赛-2018.11.7

    NOIP模拟赛 如果用命令行编译程序可以发现没加头文件之类的错误. 如果用命令行编译程序可以发现没加头文件之类的错误. 如果用命令行编译程序可以发现没加头文件之类的错误. 编译之前另存一份,听说如果敲 ...

随机推荐

  1. hdu5791 TWO

    hdu5791 TWO 题意 给你两个数串 问你两个数串有多少子串一致 子串不一定是连续的 解法 我们设 \(dp[i][j]\) 表示A串匹配到 i 位,B串匹配到 j 位,一致的子串数.那么我们有 ...

  2. MySQL的读写分离的几种选择

    MySQL的读写分离的几种选择 MySQL主从复制(Master-Slave)与读写分离(MySQL-Proxy)实践 原址如下: http://heylinux.com/archives/1004. ...

  3. 2019-03-18 Python time 将2015年11月20日转换为2015-11-20

    #ReportingDate = soup.select('body > div.main > div > div.ctr > div.recruit > ul > ...

  4. AjAX 常用参数

    1.url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. 2.type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如 ...

  5. Linux学习总结(16)——CentOS 下 Nginx + Tomcat 配置负载均衡

    最近在读埃隆·马斯克传记,他说「我认为现在有非常多的聪明人都在致力于互联网」. 仔细一想,好像真的是这样的. 我问了自己一个问题:如果你不敲代码了,你能做什么? 答案令人极其恐怖.吓得我赶紧又去写了一 ...

  6. Eclipse配置Maven私服

    Eclipse配置Maven私服 前言: 搭建Maven私有仓库的主要目的,是为了在团队多人开发时,只要内网的私有仓库有下载过依赖的jar包,就直接从私有仓库获取,不再通过外网的中央仓库.如果私服上面 ...

  7. 关于VMNet1、VMNet8、

    关于vmnet1~~~~~vmnet8 2008年04月11日 星期五 23:18 先说vmnet0,实际上就是一个虚拟的网桥,这个网桥有很若干个端口,一个端口用于连接你的Host,一个端口用于连接你 ...

  8. Android内存优化之封装九宫格

    随着市场上越来越多的APP上线,好多软件对手机的内存要求也是很大,所以我们在开发的时候一定要掌握如何去优化内存,将自己的APP尽可能优化.今天我们就一起看一下九宫格的优化.下面是软件的截图 1.为了达 ...

  9. volley源代码解析(六)--HurlStack与HttpClientStack之争

    Volley中网络载入有两种方式,各自是HurlStack与HttpClientStack.我们来看Volley.java中的一段代码 if (stack == null) {//假设没有限定stac ...

  10. [Android] Android开发优化之——对界面UI的优化(2)

    在Android应用开发过程中,屏幕上控件的布局代码和程序的逻辑代码通常是分开的.界面的布局代码是放在一个独立的xml文件中的,这个文件里面是树型组织的,控制着页面的布局.通常,在这个页面中会用到很多 ...