[考试总结]noip模拟7
为啥博客园 \(\LaTeX\) 老挂???!
\(\huge{\text{菜}}\)
刚开始写 \(T1\) 的时候,在看到后缀前缀之后,直接想到 \(AC\) 自动机,在画了半个 \(trie\) 树之后:
\(\huge{\text{这题也配用AC自动机???}}\)
然后秒写一个 \(hash\),之后一发过样例,以为稳了。。。
然后。。。
\(freopen\)
还好看到了。。。
不然就暴 \(\color{red}0\) \(\color{green}0\) \(\color{blue}0\) 了
似乎 \(kmp\) 也是可以做的,然而我不明白为什么看到这一题会先想到 \(kmp\) 而不是 \(hash\)。。。
\(code\)
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;
#define debug cout<<"debug"<<endl
//#define int long long
FILE *file_eat; int scan_eat;
namespace xin_io
{
#define freopen file_eat = freopen
#define scanf scan_eat = scanf
#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;
inline void openfile() {freopen("t.txt","r",stdin);} inline void outfile() {freopen("o.txt","w",stdout);}
inline int get()
{
int s = 0,f = 1;
register char ch = gc();
while(!isdigit(ch)) { if(ch == '-') f = -1;ch = gc();}
while(isdigit(ch)) {s = s * 10 + ch - '0'; ch = gc();}
return s * f;
}
}
using namespace xin_io;
static const int maxn = 2e5+10;
#define ull unsigned long long
namespace xin
{
class xin_hash
{
public:
ull h[maxn],p[maxn];
int base;
xin_hash(): base(13331){p[0] = 1;}
inline void do_hash(char *s)
{for(register int i=1;s[i];++i)h[i] = h[i-1] * base + (s[i] - 'a' + 1),p[i] = p[i-1] * base;}
inline ull query(int l,int r)
{return h[r] - h[l-1] * p[r - l + 1];}
}ha,hb;
int T,la,lb;
char a[maxn],b[maxn];
inline short main()
{
// #ifndef ONLINE_JUDGE
// openfile();
// #endif
scanf("%d",&T);
while(T--)
{
int ans = 0;
scanf("%d%d",&la,&lb);
scanf("%s",a+1);
// cout<<a+1<<endl;
char plus; cin>>plus; //cout<<"plus = "<<plus<<endl;
for(register int i=1;i<=lb;++i)
b[i] = a[i];
b[++lb] = plus;
ha.do_hash(a); hb.do_hash(b);
// cout<<a[1]<<a[2]<<' '<<b[3]<<b[4]<<endl;
// cout<<ha.query(1,1)<<' '<<hb.query(4,4)<<endl;
int ms = min(la,lb);
// for(register int i=1;b[i];++i) cout<<b[i];
for(register int i=1;i<=ms;++i)
{
register int j = lb - i + 1;
if(ha.query(1,i) == hb.query(j,lb))
ans = i;
}
printf("%d\n",ans);
}
return 0;
}
}
signed main() {return xin::main();}
T2:
冲过 \(T1\) 之后,然后就开心地去冲 \(T2\)了,然后一眼看出 \(tarjan\) 割点板子。。。。
喜提 \(10pts\)
对于每一个割点,并不是都是有效割点,所以,我们只能标记 有效割点,其实只需要在考场代码上面加上两句话:
if(pd[y]) pd[x] = true;
还有判断上:
if((flag > 1 or x != 1) and pd[y]) cut[x] = true;
然后就是在 \(tarjan(i)\) 之前加上 pd[n] = true
。
就这???
- 真 就这
。。。。
所以你考场上为啥没想出来???
用 杠哥的话说,就是 \(\huge{\text{废*}}\)
别骂了,别骂了。。。。
所以 \(code\):
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
using namespace std;
#define debug cout<<"debug"<<endl
//#define int long long
FILE *file_eat; int scan_eat;
namespace xin_io
{
#define freopen file_eat = freopen
#define scanf scan_eat = scanf
#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;
inline void openfile() {freopen("t.txt","r",stdin);} inline void outfile() {freopen("o.txt","w",stdout);}
inline int get()
{
int s = 0,f = 1;
register char ch = gc();
while(!isdigit(ch)) { if(ch == '-') f = -1;ch = gc();}
while(isdigit(ch)) {s = s * 10 + ch - '0'; ch = gc();}
return s * f;
}
}
using namespace xin_io;
static const int maxn = 1e6+10;
#define ull unsigned long long
#include<cstring>
#define m(c,num) memset(c,num,sizeof c)
namespace xin
{
class xin_edge{public:int next,ver;} edge[maxn<<2];
int n,m;
int num;
int scc_num = 0;
int dfn[maxn],low[maxn];
int head[maxn],zhi;
inline void add(int x,int y)
{
edge[++zhi].ver = y;
edge[zhi].next = head[x]; head[x] = zhi;
}
bool vis[maxn];
bool cut[maxn];
bool pd[maxn];
inline void tarjan(int x)
{
dfn[x] = low[x] = ++num;
// cout<<"x = "<<x<<" dfn[x] = "<<dfn[x]<<endl;
int flag = 0,s = 0;
for(register int i=head[x];i;i=edge[i].next)
{
register int y = edge[i].ver;
if(!dfn[y])
{
tarjan(y);
low[x] = min(low[x],low[y]);
if(low[y] >= dfn[x])
{
flag++;
if((flag > 1 or x != 1) and pd[y]) cut[x] = 1;
}
if(pd[y]) pd[x] = 1;
}
else low[x] = min(low[x],dfn[y]);//,cout<<low[x]<<' '<<dfn[x]<<endl;
}
}
int T;
inline void clean()
{
num = zhi = 0;
m(cut,0); m(low,0); m(dfn,0); m(pd,0);
m(vis,0); m(edge,0); m(head,0);
}
inline short main()
{
#ifndef ONLINE_JUDGE
openfile();// outfile();
#endif
T = get();
for(register int cse=1;cse<=T;++cse)
{
clean();
n = get(); m = get();
for(register int i=1;i<=m;++i)
{
register int x = get(),y = get();
add(x,y); add(y,x);
}
pd[n] = 1;
for(register int i=1;i<=n;++i)
if(!dfn[i])
tarjan(i);
int cnt = 0;
for(register int i=2;i<=n-1;++i)
if(cut[i]) cnt++;//,cout<<"i = "<<i<<" cut[i] = "<<cut[i]<<endl;
if(!cnt) {printf("0\n\n");continue;}
printf("%d\n",cnt);
for(register int i=2;i<=n-1;++i)
if(cut[i]) printf("%d ",i);
printf("\n\n");
clean();
// cout<<(sizeof (edge) + sizeof(cut) + sizeof(dfn) + sizeof(low) + sizeof(vis) + sizeof(head)) / (1 << 20) <<"MB"<<endl;
}
// for(register int i=1;i<=10;++i)
// clean();
return 0;
}
}
signed main(){return xin::main();}
T3:
在以为自己切掉 \(T2\) 之后,欢快地去打 \(T3\)。。。
然后。。。
逆序对???
思考一阵子之后,然后陷入了沉思。。。。
到了考试结束的时候也没想出一个所以然来。。。
可能是太想打正解了。。。
还不如莽一个 \(40pts\) 的暴力。
。。。。。
正解就是维护一个前缀和的前缀和,对,就这样。
然后二分起点。。。
之后就没啥了。。。
所以 \(code\):
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define debug cout<<"debug"<<endl
FILE *file_eat; int scan_eat;
namespace xin_io
{
#define freopen file_eat = freopen
#define scanf scan_eat = scanf
#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;
inline void openfile() {freopen("t.txt","r",stdin);} inline void outfile() {freopen("o.txt","w",stdout);}
inline int get()
{
int s = 0,f = 1;
register char ch = gc();
while(!isdigit(ch)) { if(ch == '-') f = -1;ch = gc();}
while(isdigit(ch)) {s = s * 10 + ch - '0'; ch = gc();}
return s * f;
}
}
using namespace xin_io;
static const int maxn = 2e6+10;
#define m(c,num) memset(c,num,sizeof c)
namespace xin
{
int len,T;
char s[maxn];
int she[maxn],bhe[maxn],brhe[maxn];
int ans;
// inline int random(int x) {return (unsigned)rand() * rand() % x;}
// inline int getst(int l,int r){return random(r-2) + l;}
int srhe[maxn],rhe[maxn];
inline int query(int l,int v,int r)
{return she[v] - she[l-1] - bhe[l-1] * (rhe[v]-rhe[l-1]) + srhe[v+1] - srhe[r+1] - brhe[r+1] * (rhe[r] - rhe[v]);}
inline bool pan(int num)
{
double every = (1.175 / ((1.0 * T))) * 1.0 * num;
// cout<<every<<endl;
register double tim = ((double)clock() / (double)(CLOCKS_PER_SEC));
if(tim >= every) return false;
return true;
}
bool vis[maxn];
int num[maxn];
inline short main()
{
#ifndef ONLINE_JUDGE
openfile();
#endif
scanf("%lld",&T);
for(register int cse=1;cse<=T;++cse)
{
register int cnt = 1;
scanf("%s",s+1); ans = 0x7f7f7f7f7f7f7f7f;
len = strlen(s+1);
for(register int i=1;i <= len;i++) s[i + len] = s[i];
for(register int i=1;i <= (len * 2);i++)
{
bhe[i] = bhe[i-1]; she[i] = she[i-1]; rhe[i] = rhe[i-1];
if(s[i] == 'R') bhe[i]++;
else rhe[i] ++,she[i] += bhe[i];
// cout<<"bhe[i] = "<<bhe[i]<<" she[i] = "<<she[i]<<endl;
}
for(register int i=(len * 2);i;i--)
{
brhe[i] = brhe[i+1]; srhe[i] = srhe[i+1];
if(s[i] == 'R') brhe[i]++;
else srhe[i] += brhe[i];//,cout<<"srhe[i] = "<<srhe[i]<<endl;
}
for(register int i=1;i<=len;++i)
{
//num[i]++;
// cout<<"len = "<<len<<" i = "<<i<<endl;
// if(vis[i]) continue;vis[i] = true;
while(cnt != len + i and query(i,cnt,i + len - 1) >= query(i,cnt + 1,i + len - 1)) cnt++;
ans = min(ans,query(i,cnt,i + len - 1));
}
cout<<ans<<endl;// m(vis,0);
// for(register int i=1;i<=len;++i)
// cout<<"i = "<<i<<" num[i] = "<<num[i]<<endl;
}
return 0;
}
}
signed main() {return xin::main();}
[考试总结]noip模拟7的更多相关文章
- 6.17考试总结(NOIP模拟8)[星际旅行·砍树·超级树·求和]
6.17考试总结(NOIP模拟8) 背景 考得不咋样,有一个非常遗憾的地方:最后一题少取膜了,\(100pts->40pts\),改了这么多年的错还是头一回看见以下的情景... T1星际旅行 前 ...
- 5.23考试总结(NOIP模拟2)
5.23考试总结(NOIP模拟2) 洛谷题单 看第一题第一眼,不好打呀;看第一题样例又一眼,诶,我直接一手小阶乘走人 然后就急忙去干T2T3了 后来考完一看,只有\(T1\)骗到了\(15pts\)[ ...
- 5.22考试总结(NOIP模拟1)
5.22考试总结(NOIP模拟1) 改题记录 T1 序列 题解 暴力思路很好想,分数也很好想\(QAQ\) (反正我只拿了5pts) 正解的话: 先用欧拉筛把1-n的素数筛出来 void get_Pr ...
- [考试总结]noip模拟23
因为考试过多,所以学校的博客就暂时咕掉了,放到家里来写 不过话说,vscode的markdown编辑器还是真的很好用 先把 \(noip\) 模拟 \(23\) 的总结写了吧.. 俗话说:" ...
- 2021.9.17考试总结[NOIP模拟55]
有的考试表面上自称NOIP模拟,背地里却是绍兴一中NOI模拟 吓得我直接文件打错 T1 Skip 设状态$f_i$为最后一次选$i$在$i$时的最优解.有$f_i=max_{j<i}[f_j+a ...
- 「考试」noip模拟9,11,13
9.1 辣鸡 可以把答案分成 每个矩形内部连线 和 矩形之间的连线 两部分 前半部分即为\(2(w-1)(h-1)\),后半部分可以模拟求(就是讨论四种相邻的情况) 如果\(n^2\)选择暴力模拟是有 ...
- 6.11考试总结(NOIP模拟7)
背景 时间分配与得分成反比,T1 20min 73pts,T2 1h 30pts,T3 2h 15pts(没有更新tot值,本来应该是40pts的,算是本次考试中最遗憾的地方了吧),改起来就是T3比较 ...
- 6.10考试总结(NOIP模拟6)
前言 就这题考的不咋样果然还挺难改的.. T1 辣鸡 前言 我做梦都没想到这题正解是模拟,打模拟赛的时候看错题面以为是\(n\times n\)的矩阵,喜提0pts. 解题思路 氢键的数量计算起来无非 ...
- 6.7考试总结(NOIP模拟5)
前言 昨天说好不考试来着,昨晚就晚睡颓了一会,今天遭报应了,也没好好考,考得挺烂的就不多说了. T1 string 解题思路 比赛上第一想法就是打一发sort,直接暴力,然后完美TLE40pts,这一 ...
- [考试反思]NOIP模拟测试19:洗礼
[]260 []230[]210 []200[8]170[9]160 这套题一般,数据很弱,T1T2暴力都能A,而且都是一些思维题,想不到就爆0. 原因不明,很多一直很强的人在这一次滑铁卢了,于是我个 ...
随机推荐
- 基于redis实现的四种常见的限流策略
引言 在web开发中功能是基石,除了功能以外运维和防护就是重头菜了.因为在网站运行期间可能会因为突然的访问量导致业务异常.也有可能遭受别人恶意攻击 所以我们的接口需要对流量进行限制.俗称的QPS也是对 ...
- 【C++】随机数,rand()与srand()函数
rand()函数 rand()会返回一随机数值, 范围在0至RAND_MAX 间.RAND_MAX定义在stdlib.h, 其值为2147483647. 测试代码: #include<cstdl ...
- 【C++】共用体\联合体(union)
共用体的用法与结构体差不多,只不过将关键字由struct变成了union.共用体使不同的类型变量存放到同一段内存单元中,所以共用体在同一时刻只能存储一个数据成员的值,共用体的大小等于最大成员的大小(结 ...
- docker安装nextcloud私人网盘,开启https配置证书
docker安装nextcloud私人网盘 之前一直用的百度网盘最近svip超级会员到期了,续费要¥199元,对于一个打工人的我来说有点儿贵.作为技术人的一员,我就来发挥发挥自己的长处,来搭建一个私人 ...
- csp-s模拟测试「9.14」A·B·C(三分,贪心)
博客大概咕了很久了......... T1 A 大概推下式子就好了,考试时数据点分治DFS前30点T了,然后后70分因为两数相乘爆long long然后本来可以A掉,就WA零了....... 式子推出 ...
- 最好的Kubernetes客户端Java库fabric8io,快来自定义你的操作
我最新最全的文章都在南瓜慢说 www.pkslow.com,欢迎大家来喝茶! 1 Kubernetes Java客户端 对于Kubernetes集群的操作,官方提供了命令行工具kubectl,这也是我 ...
- Spring WebFlux 教程:如何构建反应式 Web 应用程序
Spring WebFlux 教程:如何构建反应式 Web 应用程序 反应式系统提供了我们在高数据流世界中所需的无与伦比的响应能力和可扩展性.然而,反应式系统需要经过专门培训的工具和开发人员来实现这些 ...
- 可编程网络DataPath 及XDP
目录 可编程网络DataPath XDP 的基本架构 XDP 的软件要求 XDP 的硬件要求 XDP 的工作流程及使用 XDP 的工作模式 XDP 的工作流程 Hello World XDP 的应用 ...
- 一文读懂高速PCB设计跟高频放大电路应用当中的阻抗匹配原理
这一期课程当中,我们会重点介绍高频信号传输当中的阻抗匹配原理以及共基极放大电路在高频应用当中需要注意的问题,你将会初步了解频率与波长的基础知识.信号反射的基本原理.特性阻抗的基本概念以及怎么样为放大电 ...
- Lin语法(Linq对数据库操作)
一.Linq语句的应用: var queryAllCustomers = from cust in customers group cust by cust.City into custGroup ...