这个题目出的还是很偷懒。。。。

第一题。。。第二题。。。第三题。。。四。。。。

好吧。。。

这几次考得都有些问题,似乎可能是有些疲惫,脑袋也是转不太动,考完总觉得自己是能力的问题,但是改一分钟之后会发现自己硬生生把正解干成了暴力。

第一题

这个题目一眼看上去是一个很不错的贪心题目。

之后我们确实可以使用贪心来做这个题目。

其实就是我们发现一定会是先走到小的里面,然后再去折到上面。

然后其实这个题目还是可以使用 \(dp\) 来做,可是我似乎是不会。。。

#include<bits/stdc++.h>
using std::cout; using std::endl;
#define try(i,a,b) for(register signed i=a;i<=b;++i)
#define throw(i,a,b) for(register signed i=a;i>=b;--i)
#define asm(i,x) for(register signed i=head[x];i;i=edge[i].next)
namespace xin_io
{
#define sb(x) cout<<#x" = "<<x<<' '
#define jb(x) cout<<#x" = "<<x<<endl
#define debug cout<<"debug"<<endl
#define gc() p1 == p2 and (p2 = (p1 = buf) + fread(buf,1,1<<20,stdin),p1 == p2) ? EOF : *p1++
char buf[1<<20],*p1 = buf,*p2 = buf; int ak; typedef long long ll; typedef unsigned long long ull;
class xin_stream{public:template<typename type>inline xin_stream &operator >> (type &s)
{
register int f = 0;s = 0; register char ch = gc();
while(!isdigit(ch)) {f |= ch == '-'; ch = gc();}
while( isdigit(ch)) s = (s << 1) + (s << 3) + (ch xor 48),ch = gc(); return s = f ? -s : s,*this;
}}io;
}
using namespace xin_io; static const int maxn = 1e6+10,inf = 1e9+7; const ll llinf = 1e18+7;
namespace xin
{
class xin_edge{public:int next,ver;}edge[maxn];
int head[maxn],zhi = 0;
inline void add(int x,int y) {edge[++zhi].ver = y; edge[zhi].next = head[x]; head[x] = zhi;}
int n,ind[maxn];
int d[maxn],maxd[maxn];
int sum[maxn],val[maxn];
class xin_data
{
private:
friend bool operator < (xin_data x,xin_data y)
{return x.maxd < y.maxd;}
public:
int x,maxd;
xin_data(){}
xin_data(int x,int maxd):x(x),maxd(maxd){}
};
void dfs1(int x,int f)
{
d[x] = d[f] + 1; maxd[x] = d[x];
asm(i,x)
{
register int y = edge[i].ver;
if(y == f) continue;
dfs1(y,x);
maxd[x] = std::max(maxd[x],maxd[y]);
}
}
void dfs2(int x,int f)
{
std::vector < xin_data > vec; vec.clear();
asm(i,x)
{
register int y = edge[i].ver;
if(y == f) continue;
dfs2(y,x);
vec.push_back(xin_data(y,maxd[y]));
val[x] += sum[y];
}
std::sort(vec.begin(),vec.end());
try(i,0,(int)vec.size() - 1)
{
if(i and vec[i-1].maxd - d[x] < d[x]) sum[x]--,val[x] += vec[i-1].maxd - d[x];
sum[x] += sum[vec[i].x]; val[x] += val[vec[i].x];
}
}
inline short main()
{
io >> n;
try(i,1,n-1)
{
register int x,y; io >> x >> y;
add(x,y); add(y,x); ind[x] ++; ind[y] ++;
}
dfs1(1,0);
try(i,1,n) if(ind[i] == 1) sum[i] = 1;
dfs2(1,0);
cout<<val[1]<<endl;
return 0;
}
}
signed main() {return xin::main();}

第二题

似乎好像是用 \(dij\) 或者是 \(spfa\),但是我使用了 \(nb\) 方法过了。

我们有一个很 \(naive\) 的想法就是二分答案,之后每一个格子这样 \(\mathcal O(nm)\) 的去找,然后把小的那个加上需要的差值。

然后我们就很容易发现这个做法是个假的。

但是。

进行的每一次 \(\mathcal O(nm)\) 扫描,其实都是一次修正性算法。

所以每一次进行这个算法,都会更加正确。

所以我们只需要多做几次,也就是增加几个常数,然后就可以顺利过掉这个题目。

#include<bits/stdc++.h>
using std::cout; using std::endl;
#define try(i,a,b) for(register signed i=a;i<=b;++i)
#define throw(i,a,b) for(register signed i=a;i>=b;--i)
#define asm(i,x) for(register signed i=head[x];i;i=edge[i].next)
namespace xin_io
{
#define sb(x) cout<<#x" = "<<x<<' '
#define jb(x) cout<<#x" = "<<x<<endl
#define debug cout<<"debug"<<endl
#define gc() p1 == p2 and (p2 = (p1 = buf) + fread(buf,1,1<<20,stdin),p1 == p2) ? EOF : *p1++
char buf[1<<20],*p1 = buf,*p2 = buf; int ak; typedef long long ll; typedef unsigned long long ull;
class xin_stream{public:template<typename type>inline xin_stream &operator >> (type &s)
{
register int f = 0;s = 0; register char ch = gc();
while(!isdigit(ch)) {f |= ch == '-'; ch = gc();}
while( isdigit(ch)) s = (s << 1) + (s << 3) + (ch xor 48),ch = gc(); return s = f ? -s : s,*this;
}}io;
}
#define int long long
using namespace xin_io; static const int maxn = 1e6+10,inf = 1e9+7; const ll llinf = 1e18+7;
namespace xin
{
#define abs(x) (x < 0 ? -x : x)
int n,m,k;
int a[maxn/200][maxn/200],b[maxn/200][maxn/200];
inline bool check(int x)
{
register int temp = k;
try(i,1,n) try(j,1,m) b[i][j] = a[i][j];
try(cse,1,14)
try(i,1,n) try(j,1,m)
{
if(j - 1 >= 1) //(i,j-1)
{
register int cha = b[i][j] - b[i][j-1];
if(abs(cha) > x)
{
temp -= abs(cha) - x;
if(cha < 0) b[i][j] += abs(cha) - x;
else b[i][j-1] += abs(cha) - x;
}
}
if(j + 1 <= m) //(i,j+1)
{
register int cha = b[i][j] - b[i][j+1];
if(abs(cha) > x)
{
temp -= abs(cha) - x;
if(cha < 0) b[i][j] += abs(cha) - x;
else b[i][j+1] += abs(cha) - x;
}
}
if(i + 1 <= n and j - 1 >= 1) //(i+1,j-1)
{
register int cha = b[i][j] - b[i+1][j-1];
if(abs(cha) > x)
{
temp -= abs(cha) - x;
if(cha < 0) b[i][j] += abs(cha) - x;
else b[i+1][j-1] += abs(cha) - x;
}
}
if(i - 1 >= 1) //(i-1,j)
{
register int cha = b[i][j] - b[i-1][j];
if(abs(cha) > x)
{
temp -= abs(cha) - x;
if(cha < 0) b[i][j] += abs(cha) - x;
else b[i-1][j] += abs(cha) - x;
}
}
if(i -1 >= 1 and j + 1 <= m) //(i-1,j+1)
{
register int cha = b[i][j] - b[i-1][j+1];
if(abs(cha) > x)
{
temp -= abs(cha) - x;
if(cha < 0) b[i][j] += abs(cha) - x;
else b[i-1][j+1] += abs(cha) - x;
}
}
if(i + 1 <= n) //(i+1,j)
{
register int cha = b[i][j] - b[i+1][j];
if(abs(cha) > x)
{
temp -= abs(cha) - x;
if(cha < 0) b[i][j] += abs(cha) - x;
else b[i+1][j] += abs(cha) - x;
}
}
}
return temp >= 0;
}
int maxx = -inf;
inline short main()
{
io >> n >> m >>k ;
try(i,1,n) try(j,1,m) io >> a[i][j],maxx = std::max(a[i][j],maxx);
register int l = 0,r = maxx;
while(l != r - 1 and l < r)
{
register int mid = l + r >> 1;
if(check(mid)) r = mid;
else l = mid;
}
if(check(l)) cout<<l<<endl;
else cout<<r<<endl;
return 0;
}
}
signed main() {return xin::main();}

第三题

一个 \(10\) 分暴力滚粗了。。。。

第四题

一个很强的 \(dp\),到现在还是不是很理解。。。

#include<bits/stdc++.h>
using std::cout; using std::endl;
#define try(i,a,b) for(register signed i=a;i<=b;++i)
#define throw(i,a,b) for(register signed i=a;i>=b;--i)
#define asm(i,x) for(register signed i=head[x];i;i=edge[i].next)
namespace xin_io
{
#define sb(x) cout<<#x" = "<<x<<' '
#define jb(x) cout<<#x" = "<<x<<endl
#define debug cout<<"debug"<<endl
#define gc() p1 == p2 and (p2 = (p1 = buf) + fread(buf,1,1<<20,stdin),p1 == p2) ? EOF : *p1++
char buf[1<<20],*p1 = buf,*p2 = buf; int ak; typedef long long ll; typedef unsigned long long ull;
class xin_stream{public:template<typename type>inline xin_stream &operator >> (type &s)
{
register int f = 0;s = 0; register char ch = gc();
while(!isdigit(ch)) {f |= ch == '-'; ch = gc();}
while( isdigit(ch)) s = (s << 1) + (s << 3) + (ch xor 48),ch = gc(); return s = f ? -s : s,*this;
}}io;
}
using namespace xin_io; static const int maxn = 1e6+10,inf = 1e9+7; const ll llinf = 1e18+7;
#define int long long
namespace xin
{
#define fmod(x) (x -= (x >= mod) ? mod : 0)
int ans = 0;
int f[maxn/300][maxn/300],g[maxn/300][maxn/300];
int n,mod;
int sum[maxn/300][maxn/300];
inline short main()
{
io >> n >> mod; f[0][0] = 1;
try(i,1,n) try(j,1,n) f[i][j] = (f[i-1][j-1] + f[i-1][j] * j % mod),fmod(f[i][j]);
try(i,1,n) g[0][i] = 1;
try(i,1,n) try(j,1,n) g[i][j] = (g[i-1][j+1] + g[i-1][j] * j % mod),fmod(g[i][j]);
try(i,1,n) throw(j,n,1)
{
sum[i][j] = f[i-1][j] * (g[n-i][j] + 2 * (n - i * 1ll) * g[n-i-1][j] % mod) % mod;
sum[i][j] += sum[i][j+1]; fmod(sum[i][j]);
}
try(x,1,n)
{
register int ans = 0;
try(i,1,n)
{
register int temp = sum[i][x];
(temp += f[i-1][x-1] * (g[n-i][x] + 2 * (n - i * 1ll) * g[n-i-1][x] % mod) % mod); fmod(temp);
(ans += temp); fmod(ans);
}
printf("%lld ",ans);
}
return 0;
}
}
signed main() {return xin::main();}

[考试总结]noip模拟43的更多相关文章

  1. 8.18考试总结[NOIP模拟43]

    又挂了$80$ 好气哦,但要保持优雅.(草 T1 地衣体 小小的贪心:每次肯定从深度较小的点向深度较大的点转移更优. 模拟一下,把边按链接点的子树最大深度排序,发现实际上只有上一个遍历到的点是对当前考 ...

  2. 6.17考试总结(NOIP模拟8)[星际旅行·砍树·超级树·求和]

    6.17考试总结(NOIP模拟8) 背景 考得不咋样,有一个非常遗憾的地方:最后一题少取膜了,\(100pts->40pts\),改了这么多年的错还是头一回看见以下的情景... T1星际旅行 前 ...

  3. 5.23考试总结(NOIP模拟2)

    5.23考试总结(NOIP模拟2) 洛谷题单 看第一题第一眼,不好打呀;看第一题样例又一眼,诶,我直接一手小阶乘走人 然后就急忙去干T2T3了 后来考完一看,只有\(T1\)骗到了\(15pts\)[ ...

  4. 5.22考试总结(NOIP模拟1)

    5.22考试总结(NOIP模拟1) 改题记录 T1 序列 题解 暴力思路很好想,分数也很好想\(QAQ\) (反正我只拿了5pts) 正解的话: 先用欧拉筛把1-n的素数筛出来 void get_Pr ...

  5. 2021.9.17考试总结[NOIP模拟55]

    有的考试表面上自称NOIP模拟,背地里却是绍兴一中NOI模拟 吓得我直接文件打错 T1 Skip 设状态$f_i$为最后一次选$i$在$i$时的最优解.有$f_i=max_{j<i}[f_j+a ...

  6. [考试总结]noip模拟23

    因为考试过多,所以学校的博客就暂时咕掉了,放到家里来写 不过话说,vscode的markdown编辑器还是真的很好用 先把 \(noip\) 模拟 \(23\) 的总结写了吧.. 俗话说:" ...

  7. 「考试」noip模拟9,11,13

    9.1 辣鸡 可以把答案分成 每个矩形内部连线 和 矩形之间的连线 两部分 前半部分即为\(2(w-1)(h-1)\),后半部分可以模拟求(就是讨论四种相邻的情况) 如果\(n^2\)选择暴力模拟是有 ...

  8. 6.11考试总结(NOIP模拟7)

    背景 时间分配与得分成反比,T1 20min 73pts,T2 1h 30pts,T3 2h 15pts(没有更新tot值,本来应该是40pts的,算是本次考试中最遗憾的地方了吧),改起来就是T3比较 ...

  9. 6.10考试总结(NOIP模拟6)

    前言 就这题考的不咋样果然还挺难改的.. T1 辣鸡 前言 我做梦都没想到这题正解是模拟,打模拟赛的时候看错题面以为是\(n\times n\)的矩阵,喜提0pts. 解题思路 氢键的数量计算起来无非 ...

随机推荐

  1. SpringCloud升级之路2020.0.x版-3.Eureka Server 与 API 网关要考虑的问题

    本系列为之前系列的整理重启版,随着项目的发展以及项目中的使用,之前系列里面很多东西发生了变化,并且还有一些东西之前系列并没有提到,所以重启这个系列重新整理下,欢迎各位留言交流,谢谢!~ 之前我们提到了 ...

  2. OpenGL学习笔记(四)纹理

    目录 要完成的纹理效果 纹理环绕方式 纹理过滤 多级渐远纹理 加载与创建纹理 stb_image库的使用方法 生成纹理对象 应用纹理 纹理单元 参考资料:OpenGL中文翻译 要完成的纹理效果 纹理是 ...

  3. 【水】Dev-c++黑暗模式教程

    前言 大家有没有觉得盯着Dev-c++那个白花花的背景盯久了之后会觉得眼睛不舒服-- 本人今天就来给大家带来一个黑暗模式的Dev-c++,可以让眼睛没那么难受(本人亲测有效) 效果如下图(猛男警告): ...

  4. firewalld防火墙基础

    目录 一.firewalld 概述 二.firewalld与iptables 的区别 三.firewalld 区域概念 四.Firewalld数据处理流程 五.Firewalld检查数据包的源地址的规 ...

  5. C++STL—string类

    string容器 1.1 string容器的基本概念 string容器是一个类 这个容器中有一个指针,指针维护了一个数组 string容器提供copy.find.insert.replace等等功能 ...

  6. goproxy.io

    goproxy.io 是全球最早的 Go modules 镜像代理服务之一, 采用 CDN 加速服务为开发者提供依赖下载, 该服务由一批热爱开源, 热爱 Go 语言的年轻人开发维护.从 Go 1.11 ...

  7. Linux连接工具final配置

    Linux连接工具 putty .CRT.XShell 在terminal里面敲不太方便,所以需要一款连接工具 这是一款美观医用的网络服务管理软件 安装final shell Windows版下载地址 ...

  8. MyBatis-Plus QueryWrapper及LambdaQueryWrapper的使用

    转载自 MyBatis-Plus QueryWrapper及LambdaQueryWrapper的使用 LambdaQueryWrapper https://blog.csdn.net/lt32603 ...

  9. Swagger在线文档使用教程

    springboot整合Swagger2 1.首先创建一个springboot工程,在pom文件内导入依赖   <!--swagger依赖-->      <!--Swagger2- ...

  10. 010 FPGA千兆网UDP通信【转载】

    一.以太网帧格式 图8‑12以太网帧格式 表8‑5以太网帧格式说明 类别 字节数 说明 前导码(Preamble) 8 连续 7 个 8'h55 加 1 个 8'hd5,表示一个帧的开始,用于双方设备 ...