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分我大概 ...
随机推荐
- vue+cesiumjs的环境搭建【script引入】
[可以看我的博客里另外一篇----- import引入 ,可以不用script引入] 最近做项目要用到cesium,然后参照网上的一些步骤,最后发现报错了,其中有两种错比较多: ① This dep ...
- Linux环境下安装PHP的mbstring模块
cd /home/local/php-5.6.25/ext/mbstring/usr/local/php/bin/phpize./configure --with-php-config=/usr/lo ...
- TrMemo控件
unit TrMemo; {$R-} interface uses Windows, Messages, Controls, StdCtrls, Classes; const TMWM__Specia ...
- NX二次开发-Block UI C++界面Object Color Picker(对象颜色拾取器)控件的获取(持续补充)
Object Color Picker(对象颜色拾取器)控件的获取 NX9+VS2012 #include <uf.h> #include <uf_obj.h> UF_init ...
- docker仓库管理(9)
使用公共 Registry Docker Hub 是 Docker 公司维护的公共 Registry.用户可以将自己的镜像保存到 Docker Hub 免费的 repository 中.如果不希望别人 ...
- (2)centos7 图形界面
1.登录 2.先安装MATE可视化桌面 yum groups install "MATE Desktop" 选择y 3.安装X Window System:图形接口 yum gro ...
- bigdecimal解决小数间的加减乘除
public class bigdecimal { public static BigDecimal div(double v1,double v2){ BigDecimal b1=new BigDe ...
- c# 使用 java的 rsa 进行签名
/// <summary> /// 类名:RSAFromPkcs8 /// 功能:RSA加密.解密.签名.验签 /// 详细:该类对Java生成的密钥进行解密和签名以及验签专用类,不需要修 ...
- Linux两台机器简历信任
cd ~/.ssh ssh-keygen -t rsa scp ./id_rsa.pub root@192.168.1.1:/root/.ssh/authorized_keys
- python 实现异常退出
https://blog.csdn.net/u013385362/article/details/81206822 有时当一个条件成立的情况下,需要终止程序,可以使用sys.exit()退出程序.sy ...