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

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

好吧。。。

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

第一题

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

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

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

然后其实这个题目还是可以使用 \(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. 那些 Unix 命令替代品们「GitHub 热点速览 v.21.32」

    作者:HelloGitHub-小鱼干 好用的 Unix 命令替代工具能让你事半功倍,例如,bat 便是个带着高亮特性的加强版 cat,就像你用了 oh my zsh 之后便会感受到它的强大.同样好用的 ...

  2. 制作Java桌面程序的一键安装包

    一.简介 这个打包程序主要包含了对Java程序的普通打包.对程序的管理员权限设置.因为自己打包的时候要求程序在32位操作系统和64位操作系统下都能使用,所以有些打包步骤和设置都不相同.打包过程中主要使 ...

  3. @Value(value="${***.***}")配置文件赋值给static静态变量

    public static String topicName; @Value("${activemq.topicName}") public void setTopicName(S ...

  4. netty系列之:使用UDP协议

    目录 简介 UDP协议 String和ByteBuf的转换 构建DatagramPacket 启动客户端和服务器 总结 简介 在之前的系列文章中,我们到了使用netty做聊天服务器,聊天服务器使用的S ...

  5. 如何在idea中配置Tomcat服务器

    .IDEA 中动态 web 工程的操作         a)IDEA 中如何创建动态 web 工程        1.创建一个新模块: 2.选择你要创建什么类型的模块 3.输入你的模块名,点击[Fin ...

  6. 跟我一起写 Makefile(九)

    使用函数 ---- 在Makefile中可以使用函数来处理变量,从而让我们的命令或是规则更为的灵活和具有智能.make所支持的函数也不算很多,不过已经足够我们的操作了.函数调用后,函数的返回值可以当做 ...

  7. 消息协议AMQP 与 JMS对比

    https://blog.csdn.net/hpttlook/article/details/23391967 https://www.jianshu.com/p/6e6821604efc https ...

  8. Servelt&&JSP进阶

    Servlet与JSP进阶 来自mkw的视频课程的总结 1.前言 内容包括 掌握Java Web核心特性,Servlet核心对象以及JSP九大内置对象.主要有以下的内容: 请求结构 && ...

  9. 附件携马之CS免杀shellcode过国内主流杀软

    0x01 写在前面 其实去年已经写过类似的文章,但是久没用了,难免有些生疏.所谓温故而知新,因此再详细的记录一下,一方面可以给各位看官做个分享,另一方面等到用时也不至于出现临阵磨枪的尴尬场面. 0x0 ...

  10. STM32—重定向printf和getchar函数到串口

    在STM32测试串口的时候经常需要在开发板和上位机之间传输数据,我们可以用c语言中的printf()函数和getchar()函数来简化传输. 以printf()为例: printf()函数实际上是一个 ...