noip19
sb\(O(n^{2})\)传参
T1
暴力一会儿就码好,结果..

祭奠一下死去的代码
died
#include<cstdio>
#define MAX 1010
#define re register
namespace OMA
{
int n,q;
int r,c,l,s;
struct martix
{
int ar[MAX][MAX];
inline friend martix operator +(martix a,int add)
{
for(re int i=r; i<=r+l-1; i++)
{
for(re int j=c; j<=i-r+c; j++)
{ a.ar[i][j] += add; }
}
return a;
}
inline int ans()
{
int sum = 0;
for(re int i=1; i<=n; i++)
{
for(re int j=1; j<=n; j++)
{ sum ^= ar[i][j]; }
}
return sum;
}
inline void print()
{
for(re int i=1; i<=n; i++)
{
for(re int j=1; j<=n; j++)
{
printf("%d ",ar[i][j]);
}
printf("\n");
}
}
}u;
inline int read()
{
int s=0,w=1; char ch=getchar();
while(ch<'0'||ch>'9'){ if(ch=='-')w=-1; ch=getchar(); }
while(ch>='0'&&ch<='9'){ s=s*10+ch-'0'; ch=getchar(); }
return s*w;
}
signed main()
{
n = read(),q = read();
for(re int i=1; i<=q; i++)
{ r = read(),c = read(),l = read(),s = read(); u = u+s; }
//u.print();
printf("%d\n",u.ans());
return 0;
}
}
signed main()
{ return OMA::main(); }
好吧,其实是我传参的时候传了个1000*1000的矩阵进去,然后就炸了,我真傻,真的打暴力还整花活,还打挂了,给1pts都算便宜我了。
正解:
差分。
Code
#include<cstdio>
#define MAX 2010
#define re register
#define int long long
namespace OMA
{
int n,q,ans;
int r,c,l,s;
int sum[MAX][MAX][2];
inline int read()
{
int s=0,w=1; char ch=getchar();
while(ch<'0'||ch>'9'){ if(ch=='-')w=-1; ch=getchar(); }
while(ch>='0'&&ch<='9'){ s=s*10+ch-'0'; ch=getchar(); }
return s*w;
}
signed main()
{
n = read(),q = read();
for(re int i=1; i<=q; i++)
{
r = read(),c = read(),l = read(),s = read();
sum[r][c][0] += s,sum[r+l][c][0] -= s;
sum[r][c+1][1] -= s,sum[r+l][c+l+1][1] += s;
}
for(re int i=1; i<=n; i++)
{
int tmp = 0;
for(re int j=1; j<=n; j++)
{
sum[i][j][0] += sum[i-1][j][0],sum[i][j][1] += sum[i-1][j-1][1];
ans ^= tmp += (sum[i][j][0]+sum[i][j][1]);
}
}
printf("%lld\n",ans);
return 0;
}
}
signed main()
{ return OMA::main(); }
T2
考场一看期望直接跳
明显的状压,但更明显的是,数组开不下,所以考虑map,但是会TLE几个点,所以考虑手写hash表,可是太慢了,所以考虑特判,很明显,对于 \(k=n\) 或 \(k=n-1\) 的点,答案即为白色球的个数。特判一下就好,跑得还飞快
特判前:

优化特判后:

Code
#include<cstdio>
#include<cstring>
#include<iostream>
#define re register
#define seed 1000007
namespace OMA
{
struct Hash_map
{
struct node
{
int next;
int len;
int to;
double v;
}star[seed];
int len,cnt,head[seed];
inline double &operator [](int sta)
{
int key = 1LL*sta*len%seed;
for(re int i=head[key]; i; i=star[i].next)
{
if(star[i].to==sta&&star[i].len==len)
{ return star[i].v; }
}
return star[++cnt] = (node){head[key],len,sta,-1},head[key] = cnt,star[cnt].v;
}
}map;
int n,k;
inline double dfs(int len,int sta)
{
if(len==n-k)
{ return 0; }
map.len = len;
if(map[sta]>-1.0)
{ return map[sta]; }
int temp,tmp[50];
map[temp = sta] = 0;
for(re int i=1; i<=len; i++)
{ tmp[i] = temp&1,temp >>= 1; }
for(re int i=1; i<=len/2; i++)
{
double tmp1 = dfs(len-1,((sta>>(len-i+1))<<(len-i))|(sta&((1<<len-i)-1)))+tmp[len-i+1];
double tmp2 = dfs(len-1,((sta>>i)<<(i-1))|(sta&((1<<i-1)-1)))+tmp[i];
map.len = len,map[sta] += 2.0/len*std::max(tmp1,tmp2);
}
if(len&1)
{
double tmp1 = dfs(len-1,(sta>>(len-((len>>1)+1)+1))<<(len-((len>>1)+1))|(sta&((1<<(len-((len>>1)+1)))-1)))+tmp[len/2+1];
map.len = len,map[sta] += 1.0/len*tmp1;
}
return map[sta];
}
int sta,cnt;
char ch[50];
signed main()
{
scanf("%d%d%s",&n,&k,ch+1);
for(re int i=1; i<=n; i++)
{ sta <<= 1; if(ch[i]=='W'){ cnt++,sta++; } }
if(k&&(k==n||k==n-1))
{ printf("%0.10lf\n",(double)cnt); return 0; }
printf("%0.10lf\n",dfs(n,sta));
return 0;
}
}
signed main()
{ return OMA::main(); }
T3
考试的时候奔着1pts的点,结果加了个判断,0pts,你骗分还特判个什么啊
正解:
是个树形dp
快考试了,先咕了
Code
#include<cstdio>
#define MAX 100010
#define re register
#define INF 114514810
namespace OMA
{
int n;
struct Graph
{
int next;
int to;
int w;
}edge[MAX<<1];
int cnt=1,head[MAX];
struct node
{
int a,b;
friend bool operator <(const node &a,const node &b)
{ return a.a==b.a?a.b<b.b:a.a<b.a; }
}dp[MAX][2];
inline int read()
{
int s=0,w=1; char ch=getchar();
while(ch<'0'||ch>'9'){ if(ch=='-')w=-1; ch=getchar(); }
while(ch>='0'&&ch<='9'){ s=s*10+ch-'0'; ch=getchar(); }
return s*w;
}
inline void add(int u,int v,int w)
{
edge[++cnt].next = head[u];
edge[cnt].to = v;
edge[cnt].w = w;
head[u] = cnt;
}
inline node calc(node a,node b)
{ return (node){a.a+b.a,a.b+b.b}; }
inline node min(node a,node b)
{ return a<b?a:b; }
inline void dfs(int u,int fa,int w)
{
node a = (node){INF,INF},b = (node){0,0};
for(re int i=head[u]; i; i=edge[i].next)
{
int v = edge[i].to,w = edge[i].w;
if(v!=fa)
{
dfs(v,u,w);
node tmp1 = min(calc(a,dp[v][0]),calc(b,dp[v][1]));
node tmp2 = min(calc(b,dp[v][0]),calc(a,dp[v][1]));
a = tmp1,b = tmp2;
}
}
if(w==1)
{ dp[u][0] = (node){INF,INF}; }
else
{ dp[u][0] = min(b,(node){a.a+1,a.b}); }
if(!w)
{ dp[u][1] = (node){INF,INF}; }
else
{ dp[u][1] = min((node){a.a,a.b+1},(node){b.a+1,b.b+1}); }
}
inline int w(int c,int d)
{ return d==2?d:c!=d; }
signed main()
{
n = read();
for(re int i=1; i<=n-1; i++)
{
int u = read(),v = read(),c = read(),d = read();
add(u,v,w(c,d)),add(v,u,w(c,d));
}
dfs(1,0,2);
printf("%d %d\n",dp[1][0].a>>1,dp[1][0].b);
return 0;
}
}
signed main()
{ return OMA::main(); }
noip19的更多相关文章
- 20210718 noip19
考场 去年考过这场,心态直接爆炸 T1 一眼 T2 当初是我讲的,基本都记得(flag) T3 只记得是树形 DP,但觉得 rush 完前两题后用大量时间应该能搞出来 结果 T2 写了好久,还写假了. ...
- 20210716考试-NOIP19
u,v,w. 这场考过. T1 u 差分裸题 #include<bits/stdc++.h> using namespace std; const int N=5000; int n,m; ...
随机推荐
- 前端009-vue框架
vue-admin-element https://panjiachen.github.io/vue-element-admin-site/zh/ 基于vue的生态做的很好,提供的很多的文档,中文.并 ...
- Linux必备命令 - 常用命令集
默认进入系统,我们会看到这样的字符: [root@localhost ~]#,其中#代表当前是root用户登录,如果是$表示当前为普通用户.cd 命令 cd /home :解析:进入/home目录 ...
- [刘阳Java]_Spring IOC程序代码如何编写_第3讲
第2讲我们介绍了Spring IOC的基本原理,这篇文章告诉大家Spring IOC程序代码是如何编写的,从而可以更好的理解IOC和DI的概念(所有的Java类的初始化工作扔给Spring框架,一个J ...
- js浮点数保留位数方法封装
大家在平时业务中应该经常跟小数打交道吧,有没有被小数点的保留位数问题搞得头疼啊.比如,保留一位小数,保留俩位小数,保留三位小数,向上取整.四舍五入等等. 而我最近在项目中正好遇到类似的问题:有的地方要 ...
- Java 使用新方法打印Word文档
前言 我曾写过一篇文章,它主要介绍了如何通过物理打印机和虚拟打印机来打印Word文档.今天这篇教程将介绍一种新的方法来实现对Word文档的打印. 此次使用到的类库仍然是Spire.Doc for Ja ...
- 版本号是通过import合并而来的,不是继承来的
- shiro反序列化550、721
shiro550反序列化 获取docker镜像 docker pull medicean/vulapps:s_shiro_1 重启docker systemctl restart docker 启动d ...
- SpringBoot 默认json解析器详解和字段序列化自定义
前言 在我们开发项目API接口的时候,一些没有数据的字段会默认返回NULL,数字类型也会是NULL,这个时候前端希望字符串能够统一返回空字符,数字默认返回0,那我们就需要自定义json序列化处理 Sp ...
- etcd raft 处理流程图系列2-transport
本章给出了raftexample中使用的传输层代码,补全了上一节中传输层与raft节点(raft server和channel server)的交互细节.下图中流程的核心在于传输层中的streamRt ...
- 使用C#winform编写渗透测试工具--SQL注入
使用C#winform编写渗透测试工具--SQL注入 本篇文章主要介绍使用C#winform编写渗透测试工具,实现SQL注入的功能.使用python编写SQL注入脚本,基于get显错注入的方式进行数据 ...