01(5.10 00:00~5.17 23.59)
Karieciation · · 休闲·娱乐
坚持的第二周。
NOIP 2013 模拟(补档 00)
这场是简单的,另外加上基本上都做过,没啥难点速通了。但是华容道如果跑不过
转圈游戏
式子推出来就结束了:
#include <bits/stdc++.h>
#define LF putchar('\n')
#define SP putchar(' ')
#define ui long long
#define N 1000005
#define INF 0x3f3f3f3f
#define mod 1000000007
using namespace std;
template<typename T> void read(T& x) {
x=0; char ch=getchar(); bool f=0; while(ch<'0' || ch>'9') { if(ch=='-') f=1; ch=getchar(); }
while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch&15), ch=getchar(); if(f) x=-x;
}
template<typename T, typename... Args> void read(T& x, Args&... args) { read(x); read(args...); }
template<typename T> void write(T x) {
if(x==0) { putchar('0'); return ; } if(x<0) { putchar('-'); x=-x; }
ui a[25], t=0; while(x) a[++t]=x%10, x/=10; while(t) putchar(a[t--]|48);
}
template<typename T, typename... Ts> void write(T x, Ts... args) { write(x); if(sizeof...(args)!=0) { SP; write(args...); } }
ui n, m, k, x;
ui qp(ui a, ui b) {
ui ans=1;
while(b) {
if(b&1) ans=ans*a%n;
a=a*a%n, b>>=1;
}
return ans;
}
int main() {
read(n, m, k, x);
x=(m*qp(10, k)+x)%n;
write(x);LF;
return 0;
}
/*
3 6 9 2 5 8 1 4 7 0
*/
::::
积木大赛
先开的这个,所以先说这个。答案是
#include <bits/stdc++.h>
#define LF putchar('\n')
#define SP putchar(' ')
#define ll long long
#define ui unsigned int
#define N 1000005
#define INF 0x3f3f3f3f
#define mod 1000000007
using namespace std;
template<typename T> void read(T& x) {
x=0; char ch=getchar(); bool f=0; while(ch<'0' || ch>'9') { if(ch=='-') f=1; ch=getchar(); }
while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch&15), ch=getchar(); if(f) x=-x;
}
template<typename T, typename... Args> void read(T& x, Args&... args) { read(x); read(args...); }
template<typename T> void write(T x) {
if(x==0) { putchar('0'); return ; } if(x<0) { putchar('-'); x=-x; }
ui a[25], t=0; while(x) a[++t]=x%10, x/=10; while(t) putchar(a[t--]|48);
}
template<typename T, typename... Ts> void write(T x, Ts... args) { write(x); if(sizeof...(args)!=0) { SP; write(args...); } }
ui n, a[N], s, c;
int main() {
read(n);
for(ui i=1; i<=n; ++i) {
read(a[i]);
if(a[i]>=a[i-1]) c=a[i];
else s+=c-a[i], c=a[i];
}
write(s+c);LF;
return 0;
}
::::
花匠
这个第一眼感觉很简单,感觉咋写都能过,所以瞎写了会儿发现这个东西就是统了个类似于“山峰”“山谷”的玩意,去重后统计,因为连续相同的多余的无意义,式子是
#include <bits/stdc++.h>
#define LF putchar('\n')
#define SP putchar(' ')
#define ll long long
#define ui unsigned int
#define N 2000005
#define INF 0x3f3f3f3f
#define mod 1000000007
using namespace std;
template<typename T> void read(T& x) {
x=0; char ch=getchar(); bool f=0; while(ch<'0' || ch>'9') { if(ch=='-') f=1; ch=getchar(); }
while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch&15), ch=getchar(); if(f) x=-x;
}
template<typename T, typename... Args> void read(T& x, Args&... args) { read(x); read(args...); }
template<typename T> void write(T x) {
if(x==0) { putchar('0'); return ; } if(x<0) { putchar('-'); x=-x; }
ui a[25], t=0; while(x) a[++t]=x%10, x/=10; while(t) putchar(a[t--]|48);
}
template<typename T, typename... Ts> void write(T x, Ts... args) { write(x); if(sizeof...(args)!=0) { SP; write(args...); } }
ui n, a[N], cnt=2, c=1;
bool f1, f2;
void solve() {
read(n);
for(ui i=1; i<=n; ++i)
read(a[i]);
for(ui i=2; i<=n; ++i) if(a[i]!=a[i-1]) a[++c]=a[i];
n=c;
for(ui i=2; i<n; ++i) {
if(a[i]>a[i-1]&&a[i]>a[i+1]) ++cnt;
if(a[i]<a[i-1]&&a[i]<a[i+1]) ++cnt;
}
if(n==1) --cnt;
write(cnt);
}
int main() {
solve();
return 0;
}
::::
货车运输
开始做之前做过的题,这个直接默写了,没啥技术含量,不讲了。 ::::success[代码]
#include <bits/stdc++.h>
#define LF putchar('\n')
#define ui unsigned int
#define N 200005
using namespace std;
template<typename T> void read(T& x) {
x=0;
char ch=getchar();
while(ch<'0' || ch>'9') ch=getchar();
while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch&15), ch=getchar();
}
template<typename T, typename... Args> void read(T& x, Args&... args) {
read(x);
read(args...);
}
template<typename T> void write(T x) {
if(x==0) return (void)putchar('0');
ui a[25], t=0;
while(x) a[++t]=x%10, x/=10;
while(t) putchar(a[t--]|48);
}
struct Edge { ui to, nxt, w; } edge[N<<1];
struct EDGE {
ui x, y, z;
void Rd() {
read(x, y, z);
}
bool operator < (const EDGE& a) const {
return z>a.z;
};
} e[N];
ui n, m, x, y, head[N], idx, f[N], fat[N][16], g[N][16], dep[N];
void add(const ui u, const ui v, const ui w) {
edge[++idx].to=v, edge[idx].nxt=head[u], edge[idx].w=w, head[u]=idx;
}
ui Find(const ui x) {
return x==f[x] ? x : f[x]=Find(f[x]);
}
void dfs(const ui u, const ui fa) {
fat[u][0]=fa, dep[u]=dep[fa]+1;
for(ui i=1, j=0; i<16; ++i, ++j)
fat[u][i]=fat[fat[u][j]][j], g[u][i]=min(g[u][j], g[fat[u][j]][j]);
for(ui i=head[u]; i; i=edge[i].nxt) {
const ui v=edge[i].to;
if(v==fa) continue;
g[v][0]=edge[i].w;
dfs(v, u);
}
}
ui fun(ui x, ui y) {
if(dep[x]<dep[y]) swap(x, y);
ui r=dep[x]-dep[y], res=1e9, t=0;
while(r) {
if(r&1) res=min(res, g[x][t]), x=fat[x][t];
++t, r>>=1;
}
if(x==y) return res;
for(ui i=15; ~i; --i)
if(fat[x][i]!=fat[y][i])
res=min(res, min(g[x][i], g[y][i])), x=fat[x][i], y=fat[y][i];
return min(res, min(g[x][0], g[y][0]));
}
int main() {
read(n, m);
for(ui i=1; i<=n; ++i) f[i]=i;
for(ui i=1; i<=m; ++i) e[i].Rd();
sort(e+1, e+1+m);
for(ui i=1; i<=m; ++i) {
x=Find(e[i].x), y=Find(e[i].y);
if(x==y) continue;
add(e[i].x, e[i].y, e[i].z);
add(e[i].y, e[i].x, e[i].z);
f[y]=x;
}
for(ui i=1; i<=n; ++i) if(Find(i)==i) dfs(i, 0);
read(m);
while(m--) {
read(x, y);
if(Find(x)!=Find(y)) puts("-1");
else write(fun(x, y)), LF;
}
return 0;
}
::::
火柴排队
之前做过,但是赛场上急急瞎写,但是过了。它本质上是个类似于逆序对的玩意,我没写这个,思路可能大致相同。我做了个类似于前缀基准的东西,这个基准是表示这个位置是否换到正确位置去了,由于我们从前往后固定,所以我们可以认为这里成空位了,并且让整体后移了一下,你用树状数组把基准动态统下来,你对着这个基准推一下式子就做好了。 ::::success[代码]
#include <bits/stdc++.h>
#define LF putchar('\n')
#define SP putchar(' ')
#define ll long long
#define ui unsigned int
#define N 1000005
#define mod 99999997
using namespace std;
template<typename T> void read(T& x) {
x=0; char ch=getchar(); bool f=0; while(ch<'0' || ch>'9') { if(ch=='-') f=1; ch=getchar(); }
while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch&15), ch=getchar(); if(f) x=-x;
}
template<typename T, typename... Args> void read(T& x, Args&... args) { read(x); read(args...); }
template<typename T> void write(T x) {
if(x==0) { putchar('0'); return ; } if(x<0) { putchar('-'); x=-x; }
ui a[25], t=0; while(x) a[++t]=x%10, x/=10; while(t) putchar(a[t--]|48);
}
template<typename T, typename... Ts> void write(T x, Ts... args) { write(x); if(sizeof...(args)!=0) { SP; write(args...); } }
ui n, a[N], b[N], c[N], g[N], f[N], ans, cnt, need[N], Cnt[N];
map<ui, ui> p;
bool cmp(ui x, ui y) {
return a[x]<a[y];
}
void update(ui i) {
for(; i<=n; i+=(i&-i)) ++f[i];
}
ui getsum(ui i) {
ui res=0;
while(i) res+=f[i], i-=(i&-i);
return res;
}
ui ad(const ui x) {
return x<mod ? x : x-mod;
}
vector<ui> G[N];
int main() {
read(n);
for(ui i=1; i<=n; ++i) {
read(a[i]);
g[i]=i;
}
sort(g+1, g+1+n, cmp);
for(ui i=1; i<=n; ++i) {
read(b[i]);
c[i]=b[i];
}
sort(c+1, c+1+n);
p[c[1]]=cnt=1;
for(ui i=2; i<=n; ++i) if(c[i]!=c[i-1]) p[c[i]]=++cnt;
for(ui i=1; i<=n; ++i)
need[g[i]]=p[c[i]];
for(ui i=1; i<=n; ++i)
G[b[i]=p[b[i]]].push_back(i);
for(ui i=1; i<=n; ++i) {
const ui j=G[need[i]][Cnt[need[i]]++];
ans=ad(ans+getsum(n-j+1)+j-i);
update(n-j+1);
}
write(ans);
return 0;
}
::::
华容道
没做过,场上如果写正解我肯定死亡了,但是数据量太小,暴力 bfs 过去了,没啥技术含量,看看代码。 ::::success[代码]
#include <cstdio>
#include <cstring>
#define LF putchar('\n')
#define ui int
#define N 35
#define M 1000005
#define INF 0x3f3f3f3f
const ui dx[5]= { 0, 1, 0, -1, 0 }, dy[5]= { 1, 0, -1, 0, 0 };
template<typename T> void read(T& x) {
x=0;
char ch=getchar();
while(ch<'0' || ch>'9') ch=getchar();
while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch&15), ch=getchar();
}
template<typename T, typename... Args> void read(T& x, Args&... args) {
read(x);
read(args...);
}
template<typename T> void write(T x) {
if(x==0) { putchar('0'); return ; }
if(x<0) { putchar('-'); x=-x; }
ui a[9], t=0;
while(x) a[++t]=x%10, x/=10;
while(t) putchar(a[t--]|48);
}
ui n, m, q, a[N][N], x, y, sx, sy, ex, ey, f[N][N][N][N], h, t, qx[M], qy[M], qx2[M], qy2[M], v;
void add(const ui a, const ui b, const ui x, const ui y, const ui v) {
qx[++t]=a, qy[t]=b, qx2[t]=x, qy2[t]=y, f[a][b][x][y]=v;
}
bool check(const ui x, const ui y) {
return x>0&&y>0&&x<=n&&y<=m&&a[x][y];
}
ui bfs() {
memset(f, INF, sizeof f);
h=t=0, add(sx, sy, x, y, 0);
if(sx==ex&&sy==ey) return 0;
while(h<t) {
sx=qx[++h], sy=qy[h], x=qx2[h], y=qy2[h], v=f[sx][sy][x][y]+1;
for(ui i=0, xx=x+dx[i], yy=y+dy[i]; i<4; xx=x+dx[++i], yy=y+dy[i])
if(xx==sx&&yy==sy) {
if(f[x][y][sx][sy]<INF) continue;
if(x==ex&&y==ey) return v;
add(x, y, sx, sy, v);
}
else if(check(xx, yy)&&f[sx][sy][xx][yy]==INF) add(sx, sy, xx, yy, v);
}
return -1;
}
int main() {
read(n, m, q);
for(ui i=1; i<=n; ++i) for(ui j=1; j<=m; ++j) read(a[i][j]);
while(q--) {
read(x, y, sx, sy, ex, ey);
if(a[x][y]&&a[sx][sy]&&a[ex][ey]) write(bfs()), LF;
else puts("-1");
}
return 0;
}
::::
NOIP 2011 模拟
成乐子了,速通完简单题后看 C,明显深度很小还写了个广搜上去死亡了。
铺地毯
如题面,找最后一个能盖到这个点的地毯输出,不然无解。 ::::success[代码]
#include <bits/stdc++.h>
#define LF putchar('\n')
#define SP putchar(' ')
#define ll long long
#define ui unsigned int
#define N 10005
#define INF 0x3f3f3f3f
#define mod 1000000007
using namespace std;
template<typename T> void read(T& x) {
x=0; char ch=getchar(); bool f=0; while(ch<'0' || ch>'9') { if(ch=='-') f=1; ch=getchar(); }
while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch&15), ch=getchar(); if(f) x=-x;
}
template<typename T, typename... Args> void read(T& x, Args&... args) { read(x); read(args...); }
template<typename T> void write(T x) {
if(x==0) { putchar('0'); return ; } if(x<0) { putchar('-'); x=-x; }
ui a[25], t=0; while(x) a[++t]=x%10, x/=10; while(t) putchar(a[t--]|48);
}
template<typename T, typename... Ts> void write(T x, Ts... args) { write(x); if(sizeof...(args)!=0) { SP; write(args...); } }
ui n, a[N], b[N], g[N], k[N], x, y;
void solve() {
read(n);
for(ui i=1; i<=n; ++i)
read(a[i], b[i], g[i], k[i]);
read(x, y);
for(ui i=n; i; --i) {
if(a[i]<=x&&b[i]<=y&&a[i]+g[i]>x&&b[i]+k[i]>y) {
write(i);
return ;
}
}
puts("-1");
}
int main() {
solve();
return 0;
}
::::
选择客栈
我想+写比我写这个总结快我能不总结这道题吗。你发现有咖啡馆可以的话我们就可以把这个咖啡馆即以前的酒店全部扔到桶里,你发现我们可以保证每个点就被扔一遍,所以总体还是
#include <bits/stdc++.h>
#define LF putchar('\n')
#define SP putchar(' ')
#define ll long long
#define ui unsigned int
#define N 2000005
#define M 10005
#define INF 0x3f3f3f3f
#define mod 1000000007
using namespace std;
template<typename T> void read(T& x) {
x=0; char ch=getchar(); bool f=0; while(ch<'0' || ch>'9') { if(ch=='-') f=1; ch=getchar(); }
while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch&15), ch=getchar(); if(f) x=-x;
}
template<typename T, typename... Args> void read(T& x, Args&... args) { read(x); read(args...); }
template<typename T> void write(T x) {
if(x==0) { putchar('0'); return ; } if(x<0) { putchar('-'); x=-x; }
ui a[25], t=0; while(x) a[++t]=x%10, x/=10; while(t) putchar(a[t--]|48);
}
template<typename T, typename... Ts> void write(T x, Ts... args) { write(x); if(sizeof...(args)!=0) { SP; write(args...); } }
ui n, k, p, a, b, c, pre, x[M], s[M], G[M];
ll ans;
void solve() {
read(n, k, p);
for(ui i=1; i<=n; ++i) {
read(a, b);
++G[a];
if(G[a]==1) x[++c]=a;
if(b<=p) {
for(ui j=1; j<=c; ++j)
s[x[j]]+=G[x[j]], G[x[j]]=0;
c=0;
ans+=s[a]-1;
}
else ans+=s[a];
}
write(ans);
}
int main() {
solve();
return 0;
}
::::