NOIp2018集训test-9-1(pm)
欢乐%你赛,大家都AK了。
1. 小澳的方阵
吸取了前几天的教训,我一往复杂的什么二维树状数组上想就立刻打住阻止自己,就可以发现它是超级大水题了。记录每一行每一列最后一次的修改,对每个格子看它所在行和列哪一个修改更靠后即可。
- //Achen
- #include<algorithm>
- #include<iostream>
- #include<cstring>
- #include<cstdlib>
- #include<vector>
- #include<cstdio>
- #include<queue>
- #include<cmath>
- #include<set>
- #include<map>
- #define Formylove return 0
- #define For(i,a,b) for(int i=(a);i<=(b);i++)
- #define Rep(i,a,b) for(int i=(a);i>=(b);i--)
- const int N=;
- typedef long long LL;
- typedef double db;
- using namespace std;
- int n,m,q,h[N][],l[N][];
- template<typename T>void read(T &x) {
- char ch=getchar(); x=; T f=;
- while(ch!='-'&&(ch<''||ch>'')) ch=getchar();
- if(ch=='-') f=-,ch=getchar();
- for(;ch>=''&&ch<='';ch=getchar()) x=x*+ch-''; x*=f;
- }
- #define ANS
- int main() {
- #ifdef ANS
- freopen("matrix.in","r",stdin);
- freopen("matrix.out","w",stdout);
- #endif
- read(n); read(m); read(q);
- For(i,,q) {
- int x,y,z;
- read(x); read(y); read(z);
- if(x==) h[y][]=z,h[y][]=i;
- else l[y][]=z,l[y][]=i;
- }
- For(i,,n) {
- For(j,,m) {
- if(h[i][]<l[j][]) printf("%d ",l[j][]);
- else printf("%d ",h[i][]);
- } puts("");
- }
- Formylove;
- }
2. 小澳的坐标系
可以暴搜或者打个n^2dp(根据竖着走上多少行,每一行走多少步,往左还是往右dp)找规律。我不会找规律,就继续yy怎么更优秀地dp。
f[i][0]表示走i步的方案,f[i][1]表示走i步且最后一步往上走的方案。
若最后一步往左走,下一步可以往左,往上 2种走法
若最后一步往右走,下一步可以往右,往上 2种走法
若最后一步往上走,下一步可以往左,往右,往上 3种走法
所以 f[i][0]=f[i-1][0]*2+f[i-1][1]
显然 f[i][1]=f[i-1][0]
这个递推方程一出来,就可以套矩乘板子了。
- //Achen
- #include<algorithm>
- #include<iostream>
- #include<cstring>
- #include<cstdlib>
- #include<vector>
- #include<cstdio>
- #include<queue>
- #include<cmath>
- #include<set>
- #include<map>
- #define Formylove return 0
- #define For(i,a,b) for(int i=(a);i<=(b);i++)
- #define Rep(i,a,b) for(int i=(a);i>=(b);i--)
- const int N=,p=1e9+;
- typedef long long LL;
- typedef double db;
- using namespace std;
- int n;
- template<typename T>void read(T &x) {
- char ch=getchar(); x=; T f=;
- while(ch!='-'&&(ch<''||ch>'')) ch=getchar();
- if(ch=='-') f=-,ch=getchar();
- for(;ch>=''&&ch<='';ch=getchar()) x=x*+ch-''; x*=f;
- }
- struct jz {
- LL a[][];
- friend jz operator *(const jz&A,const jz&B) {
- jz rs;
- For(i,,) For(j,,) {
- rs.a[i][j]=;
- For(k,,)
- (rs.a[i][j]+=A.a[i][k]*B.a[k][j]%p)%=p;
- }
- return rs;
- }
- }bs,rs;
- void ksm(int b) {
- while(b) {
- if(b&) rs=rs*bs;
- bs=bs*bs;
- b>>=;
- }
- }
- #define ANS
- int main() {
- #ifdef ANS
- freopen("coordinate.in","r",stdin);
- freopen("coordinate.out","w",stdout);
- #endif
- read(n);
- rs.a[][]=rs.a[][]=;
- rs.a[][]=rs.a[][]=;
- bs.a[][]=; bs.a[][]=;
- bs.a[][]=; bs.a[][]=;
- ksm(n-);
- LL ans=(3LL*rs.a[][]%p+1LL*rs.a[][])%p;
- printf("%lld\n",ans);
- Formylove;
- }
3.小澳的葫芦
dp[x][y]表示从1到x经过y个点的最短路。
DAG上dp,拓扑排序即可。
- //Achen
- #include<algorithm>
- #include<iostream>
- #include<cstring>
- #include<cstdlib>
- #include<vector>
- #include<cstdio>
- #include<queue>
- #include<cmath>
- #include<set>
- #include<map>
- #define Formylove return 0
- #define For(i,a,b) for(int i=(a);i<=(b);i++)
- #define Rep(i,a,b) for(int i=(a);i>=(b);i--)
- const int N=,M=;
- typedef long long LL;
- typedef double db;
- using namespace std;
- int n,m,f[N][N];
- template<typename T>void read(T &x) {
- char ch=getchar(); x=; T f=;
- while(ch!='-'&&(ch<''||ch>'')) ch=getchar();
- if(ch=='-') f=-,ch=getchar();
- for(;ch>=''&&ch<='';ch=getchar()) x=x*+ch-''; x*=f;
- }
- int ecnt,fir[N],nxt[M],to[M],val[M],in[N];
- void add(int u,int v,int w) {
- nxt[++ecnt]=fir[u]; fir[u]=ecnt; to[ecnt]=v; val[ecnt]=w; in[v]++;
- }
- queue<int>que;
- void tpsort() {
- memset(f,/,sizeof(f));
- int inf=f[][];
- f[][]=;
- For(i,,n) if(!in[i]) que.push(i);
- while(!que.empty()) {
- int x=que.front();
- que.pop();
- for(int i=fir[x];i;i=nxt[i]) {
- in[to[i]]--;
- if(!in[to[i]]) que.push(to[i]);
- For(j,,n) if(f[x][j]!=inf) {
- if(f[x][j]+val[i]<f[to[i]][j+])
- f[to[i]][j+]=f[x][j]+val[i];
- }
- }
- }
- }
- #define ANS
- int main() {
- #ifdef ANS
- freopen("calabash.in","r",stdin);
- freopen("calabash.out","w",stdout);
- #endif
- read(n); read(m);
- For(i,,m) {
- int u,v,w;
- read(u); read(v); read(w);
- add(u,v,w);
- }
- tpsort();
- db ans=1e18;
- For(i,,n) ans=min(ans,(db)f[n][i]/(1.0*i));
- printf("%lf\n",ans);
- Formylove;
- }
NOIp2018集训test-9-1(pm)的更多相关文章
- NOIp2018集训test-10-24(am&pm)
李巨连续AK三场了,我跟南瓜打赌李巨连续AK七场,南瓜赌李巨连续AK五场. DAY1 T1 qu 按题意拿stack,queue和priority_que模拟即可.特判没有元素却要取出的情况. T2 ...
- NOIp2018集训test-9-21(am/pm)
Am DAY1 抄代码 送分题 //Achen #include<bits/stdc++.h> #define For(i,a,b) for(int i=(a);i<=(b);i++ ...
- NOIp2018集训test-9-19(am&pm)
AM 这是一套在长沙考过而且我能记得全部正解的题,然后期望得分300实际得分155. T1 很套路,随便搞(我当年是怎么花大半场时间写T1并且写出现在两倍长的代码的??) //Achen #inclu ...
- NOIp2018集训test-9-22(am/pm) (联考三day1/day2)
szzq学长出的题,先orz一下. day1 倾斜的线 做过差不多的题,写在我自己的博客里,我却忘得一干二净,反而李巨记得清清楚楚我写了的. 题目就是要最小化这个东西 $|\frac{y_i-y_j} ...
- NOIp2018集训test-9-17(pm)
T1记忆(memory) 我大概是只记忆只有七秒的金鱼吧.看了下以前的代码发现真的很简单,但是考场上只打了个暴力,虽然骗了88pt.就是枚举选的是哪个串,然后vis[i]表示选了i这些位能不能猜出它, ...
- NOIp2018集训test-9-8(pm) (联考一day2)
把T1题读错了,想了一个多小时发现不可做.然后打了t2,常数不优秀.然后去打t3,lct,结果打挂爆0了. 然后今天就爆炸了. 如果这是noip我今年就可以直接回去学常规了.学常规多好,多开心. 今天 ...
- NOIp2018集训test-9-7(pm) (联考一day1)
又被辉神吊打了.今天不仅被辉神李巨吊打,还给基本上给全班垫底了. 看到T3就知道是十进制快速幂,全机房考试的当时应该就我会,结果我tm没找到递推. Orz lyc BM直接水过,Orz wys六个fo ...
- NOIp2018集训test-9-6(pm)
T1T2是洛谷原题.Orz辉神290,被辉神吊起来打. 题 1 包裹快递 二分答案.这题似乎卡精度,不开long double二分500次都过不去. //Achen #include<algor ...
- NOIp2018集训test-9-5(pm)
老张说:这套题太简单啦,你们最多两个小时就可以AK啦! 题 1 数数 我看到T1就懵了,这就是老张两个小时可以AK的题的T1?? 然后我成功地T1写了1h+,后面1h打了t2.t3暴力,就很开心. 等 ...
- NOIp2018集训test-9-2(pm)
其实这套题我爆0了,T1define 写成ddefine编译错误 T2有两个变量爆int 但是我看zwh不在悄悄地改了,我心里还是十分愧疚(没有)的.主要是林巨已经虐我125了要是再虐我200分我大概 ...
随机推荐
- Aajx调用千千音乐数据接口
前端展示截图https://images.cnblogs.com/cnblogs_com/LiuFqiang/1429011/o_D09Q55)EL1VFEIJ(GKI%7D%7DY5.png < ...
- Go: Println 与 Printf 的区别
Go 学习笔记:Println 与 Printf 的区别,以及 Printf 的详细用法 2017-12-19 15:39:05 zgh0711 阅读数 26255更多 分类专栏: Go 版权声明 ...
- 富文本 保存转义StringEscapeUtils.unescapeHtml4(
StringEscapeUtils.unescapeHtml4( [org.apache.commons.lang.StringEscapeUtils.escapeHtml(str)] [String ...
- Dart编程实例 - Const 关键字
Dart编程实例 - Const 关键字 void main() { final v1 = 12; const v2 = 13; v2 = 12; } 本文转自:http://codingdict.c ...
- 如何基于 Nacos 和 Sentinel ,实现灰度路由和流量防护一体化
基于Alibaba Nacos和Sentinel,实现灰度路由和流量防护一体化的解决方案,发布在最新的 Nepxion Discovery 5.4.0 版,具体参考: 源码主页,请访问 源码主页指南主 ...
- 简单的使用Qt的QCustomplot画图
一.新建一个widget工程 二.将Qcustomplot文件复制到项目下 三.右键qt项目增加已存在的文件 四.在.pro中添加 QT += widgets printsupport 五.在.h中添 ...
- 大牛公司的github
Google Google https://github.com/google Google Samples https://github.com/googlesamples Google Codel ...
- AcWing 143. 最大异或对 01字典树打卡
在给定的N个整数A1,A2……ANA1,A2……AN中选出两个进行xor(异或)运算,得到的结果最大是多少? 输入格式 第一行输入一个整数N. 第二行输入N个整数A1A1-ANAN. 输出格式 输出一 ...
- 30天轻松学习javaweb_修改tomcat的servlet模板
在MyEclipse目录下搜索com.genuitec.eclipse.wizards 得到搜索结果 com.genuitec.eclipse.wizards_9.0.0.me201108091322 ...
- HTML5自定义属性的设置与获取
<div id="box" aaa="bbb" data-info="hello"></div> <body& ...