2016 10 26考试 NOIP模拟赛 杂题

Time 7:50 AM -> 11:15 AM

感觉今天考完后,我的内心是崩溃的


试题
考试包


T1:

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

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即可。

呵呵

hehe
再来看一下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).

呵呵

hehe

好吧我们开始自食其力

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

很显然这张图不是一般的图(废话),我们不难发现这张图实际上是由若干个小三角形组成的(即题解中所说的三元组),那么对于
图1
这种形状的图来说,我们只能从中选取两个三角形来进行操作,从而推知,对于任意一条边,最多只有两个与之相连三角形被选取,因此,可以选择从四周向中间的123转移
设a数组记录了每个点连出去的两个点,用每个后加入点的标号表示三角形的标号,b数组代表从其余两个方向递推过来时的最大值,
2
即图中的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;
beginif a>b then exit(a);exit(b);
end;
beginassign(input,'aya.in');reset(input);assign(output,'aya.out');rewrite(output);readln(n);for i:=4 to n dobeginreadln(a[i,1],a[i,2]);if a[i,1]>a[i,2] thenbeginj:=a[i,1];a[i,1]:=a[i,2];a[i,2]:=j;end;end;for i:=n downto 4 dobeginif a[i,2]<4 thenbeginans:=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);endelsebeginif a[a[i,2],1]=a[i,1] thenbeginans:=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);endelsebeginans:=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.


zb

转载于:https://www.cnblogs.com/CtsNevermore/p/6000243.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/285746.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

2016 CCPC 杭州

A - ArcSofts Office Rearrangement 均分石子。 好像怎么分答案都一样&#xff0c;于是模拟一遍。 #include <bits/stdc.h>using namespace std; typedef long long ll;template<typename T> inline void read(T &x){ x0;T f1;char ch;do{chgetchar();if(ch-)f…

[转]RxHttp 一条链发送请求,新一代Http请求神器(一)

简介 RxHttp是基于OkHttp的二次封装&#xff0c;并于RxJava做到无缝衔接&#xff0c;一条链就能发送一个完整的请求。主要功能如下&#xff1a; 支持Get、Post、Put、Delete等任意请求方式&#xff0c;可自定义请求方式支持Json、DOM等任意数据解析方式&#xff0c;可自定义数据…

【Pix4d精品教程】Pix4d空三后处理:点云分类与过滤、DSM精编生成DEM、生成等高线案例详解

《无人机航空摄影测量精品教程》合集目录(Pix4d、CC、EPS、PhotoScan、Inpho) DEM结果预览: 等高线结果预览: Pix4d内业空三结束后,会生成点云,DOM和DSM等产品,一般情况下,DOM精度不达标(如房屋边缘有噪点)的话,可以直接在镶嵌图编辑器进行DOM的编辑,然而后处理的…

如何更好地组织最小 WEB API 代码结构

前言我们在《.NET 6新特性试用》中讲过&#xff0c;随着项目需求和复杂性的增加&#xff0c;单个文件的最小 WEB API 会变得非常臃肿。而且&#xff0c;Program.cs 应该只放启动和初始化代码。不应该包含太多 MapXXX 方法。那么&#xff0c;如何以更好的方式组织最小 WEB API 代…

C语言试题八十四之求空间两点之间的距离

📃个人主页:个人主页 🔥系列专栏:C语言试题200例目录 💬推荐一款刷算法、笔试、面经、拿大公司offer神器 👉 点击跳转进入网站 ✅作者简介:大家好,我是码莎拉蒂,CSDN博客专家(全站排名Top 50),阿里云博客专家、51CTO博客专家、华为云享专家 1、题目 定义一个表…

git分支进阶

其实git除了版本控制&#xff0c;另外一个最突出的特点就是他的分支操作。简直 丝滑~.git也是多人协作的必备武器。 通常我们正常情况下只需要master 和 develop分支就够了。 这里我们先以这两条分支作为基准&#xff0c;进行一系列的操作。 开发新功能流程 这个应该属于develo…

关于c# .net爬虫

刚开始听到爬虫这两个字眼的时候感觉挺稀奇的&#xff0c;之前并没有接触过爬虫&#xff0c;正好这会手上没事&#xff0c;于是便百度了一下。 1.网络爬虫&#xff08;又被称为网页蜘蛛&#xff0c;网络机器人&#xff0c;在FOAF社区中间&#xff0c;更经常的称为网页追逐者&am…

Google 的 Java 编码规范,参考学习!

目录 01 术语说明和指南说明 02 源文件基础 2.1 文件名 2.2 文件编码&#xff1a;UTF-8 2.3 特殊字符 03 源文件结构 3.1 许可证或版权信息 3.2 package语句 3.3 import语句 3.4 类声明 04 格式 4.1 大括号 4.3 一行一个语句 4.4 列限制&#xff1a;80 或 100 4…

MySQL Schema与数据类型的优化

选择优化的数据类型&#xff1a; 1、 更小的通常更好&#xff1a; 一般情况下&#xff0c;应该尽量使用可以正确存储数据的最小数据类型。更小的数据类型通常更快&#xff0c;因为他们占用更少的磁盘&#xff0c;内存和cpu缓存&#xff0c;并且处理时需要的cpu周期也更少。 2、…

【Pix4d精品教程】Pix4d中央子午线细化设置(测区跨两个分带)

《无人机航空摄影测量精品教程》合集目录(Pix4d、CC、EPS、PhotoScan、Inpho) 航测内业中,在自由空三结束之后,需要导入像控点,进而去刺像控点。但是当测区跨两个分带的时候(如测区正好处在3度带105和108中间),像控点可能距离靶标点很远,给刺点带来了很大难度。怎样解…

Failed:(13: Permission denied)导致访问浏览器出现Nginx 500 Internal Server Error

1 、问题 我在部署nginx反向代理服务器的时候&#xff0c;nginx.conf文件都配置好了&#xff0c;但是我在浏览器里面输入域名的时候&#xff0c;提示Nginx 500 Internal Server Error 2、分析 我们需要找到nginx输出错误日志的文件&#xff0c;在nginx.conf里面我们可以看到错…

MAUI与Blazor共享一套UI,媲美Flutter,实现Windows、macOS、Android、iOS、Web通用UI

1. 前言距离上次发《MAUI初体验&#xff1a;爽》一文已经过去2个月了&#xff0c;本计划是下半年或者明年再研究MAUI的&#xff0c;现在计划提前啦&#xff0c;因为我觉得MAUI Blazor挺有意思的&#xff1a;在Android、iOS、macOS、Windows之间共享UI&#xff0c;一处UI增加或者…

dns 报文格式

最近学习了下DNS的格式&#xff0c;发现很多内容都是转载自同一个而且说的不是很清楚&#xff0c;特再整理下具体可以查看RFC1035 http://www.ietf.org/rfc/rfc1035.txt有详细的解释对于英语理解不是很好和懒得看这么长的可以看下本文首先是DNS数据帧的格式-------------------…

input file实现批量上传

1、需求实现word批量上传。 2、使用插件jquery-form.js 3、html代码 注意 multiple"multiple" 1 <form id"frm_upload" method"post" enctype"multipart/form-data"> 2   <input type"file" id"filepath&qu…

【Pix4d精品教程】Pix4d修编正射影像DOM的两种方法案例详解

《无人机航空摄影测量精品教程》合集目录(Pix4d、CC、EPS、PhotoScan、Inpho) DOM修编前: DOM修编后: 文章摘要: Pix4d内业数据处理通常会生成点云、DSM和DOM等产品,DSM经过精编可以生成精准的DEM,而DOM一般情况下,存在比如房屋边缘被拉花,或者存在噪点的情况

删除Linux下/tmp目录引起的不正常登录系统

现象&#xff1a;/tmp占用400M的空间(里面全部是乱七八糟的东西) 动作&#xff1a;删除/tmp目录 后果&#xff1a;造成只能启动到控制台模式 应急&#xff1a; 1 创建目录&#xff1a;#mkdir /tmp 结果系统在控制台模式登录和X windows模式登录状态间反复切换&#xff0c;不能进…

C语言试题八十五之狼追兔子问题

📃个人主页:个人主页 🔥系列专栏:C语言试题200例目录 💬推荐一款刷算法、笔试、面经、拿大公司offer神器 👉 点击跳转进入网站 ✅作者简介:大家好,我是码莎拉蒂,CSDN博客专家(全站排名Top 50),阿里云博客专家、51CTO博客专家、华为云享专家 1、题目 一只兔子躲…

[转]快速使用FileProvider解决Android7.0文件权限问题

升级到Android7.0之后&#xff0c;启动系统相机或者截图&#xff0c;传入URI的时候可能会导致程序闪退崩溃。这是因为7.0的新的文件权限导致的。下面是解决这个问题的快速解决方案。 问题代码 在7.0可能会出问题的代码&#xff1a; final String CACHE_IMG Environment.getExt…

终于找到了,开源的Vue3+.NET6通用管理后台!

据说80%的.NET项目都是管理后台&#xff0c;然而能用上Vue3.NET6的管理后台并不多见。这里分享一套Vue3 Axios TS Vite ElementUI Plus .NET 6 WebAPI JWT SqlSugar的前后端分离架构的通用管理后台源码数据库脚本&#xff0c;还有与之配套录制的一组视频教程&#xff0c;全部打…

【Pix4d精品教程】Pix4d模型成果导出OSGB并加载OSGB到EPS进行三维测图完美案例教程

《无人机航空摄影测量精品教程》合集目录(Pix4d、CC、EPS、PhotoScan、Inpho) 在垂直摄影中,Pix4d也可以生成漂亮的三维模型,并导出为OSGB,加载到EPS进行三维测图。首先来看生成的三维格网纹理和EPS三维模型加载效果。 Pix4d生成的三维格网纹理: EPS加载OSGB模型效果: 文…