[考试总结]noip模拟6
我好菜啊
- 真上次第二这次倒二。。。
因为昨天还没有改完所有的题所以就留到今天来写博客了
这次考试总结的教训有很多吧,反正处处体现XIN某人的laji,自己考试的是后本以为一共四个题目,三个题目都没有看懂,然而考试结束以后才发现,自己是四个题目都没有看懂。cao
又成10分XIN了
不管了,菜就是菜了。
以后看到题目中不懂的玩意儿也不应该害怕,什么曼哈顿距离,自己看看样例就知道了,不应该弃掉的,并且在手推样例认为样例有锅的时候也应该返回去去看看题目,而不是一味地认为题目有锅。。。
\(\huge{\text{菜}}\)
来自 \(\LaTeX\) 的侮辱
T1:
什么laji曼哈顿距离,反正对角线就完了。
。。。。。
然后记录每一个矩形,按照 \(x\) 的大小进行排序,之后就计算相邻矩形形成的氢键数量就 \(ok\) 了
为什么之考虑所有矩形不相连就有 \(65pts\) 啊!!!
。。。。。
code:
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
using namespace std;
#define int long long
#define debug cout<<"debug"<<endl
#define freopen eat2 = freopen
#define scanf eat1 = scanf
namespace xin_io
{
#define gc() p1 == p2 and (p2 = (p1 = buf) + fread(buf,1,1<<20,stdin),p1 == p2) ? EOF : *p1++
#define scanf eat1 = scanf
#define freopen eat2 = freopen
char buf[1<<20],*p1 = buf,*p2 = buf;FILE *eat2;
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; int eat1;
static const int maxn = 1e5+10;
#include<ctime>
#include<cstring>
#define mp make_pair
#define xd xin_data
#define rp(i,x,y) for(register int i=x;i<=y;++i)
#define bd(i,x,y) for(register int i=x;i>=y;--i)
namespace xin
{
class xin_data
{
public:
int x1,x2,y1,y2;
friend bool operator < (xin_data x,xin_data y) {return x.x1 == y.x1 ? x.y1 < y.y1 : x.x1 < y.x1;}
}p[maxn];
int n,ans = 0;
inline int find(int x,int y)
{
int tog;
if(p[x].x2 + 1 == p[y].x1)
{
if(p[y].y1 > p[x].y2 or p[y].y2 < p[x].y1) return 0;
tog = abs(max(p[y].y2,p[x].y2) - min(p[y].y1,p[x].y1) + 1) - abs(p[y].y2 - p[x].y2) - abs(p[y].y1 - p[x].y1);
if(p[x].y1 == p[y].y1 and p[x].y2 == p[y].y2) return tog * 2;
if(p[x].y2 == p[y].y2 or p[x].y1 == p[y].y1) return tog * 2 - 1;
return tog * 2;
}
if(p[x].y2 + 1 == p[y].y1)
{
if(p[y].x1 > p[x].x2 or p[x].x1 > p[y].x2) return 0;
tog = abs(max(p[x].x2,p[y].x2) - min(p[x].x1,p[y].x1) + 1) - abs(p[x].x2 - p[y].x2) - abs(p[x].x1 - p[y].x1);
if(p[x].x1 == p[y].x1 and p[x].x2 == p[y].x2) return tog * 2;
if(p[x].x2 == p[y].x2 or p[x].x1 == p[y].x1) return tog * 2 - 1;
return tog * 2;
}
return 0;
}
inline short main()
{
#ifndef ONLINE_JUDGE
openfile();
#endif
n = get();
rp(i,1,n) p[i].x1 = get(),p[i].y1 = get(),p[i].x2 = get(),p[i].y2 = get(),ans += (p[i].x2 - p[i].x1) * (p[i].y2 - p[i].y1) * 2;
sort(p+1,p+n+1);
// rp(i,1,n) cout<<"i = "<<i<<" p[i].x1 = "<<p[i].x1<<" p[i].y1 = "<<p[i].y1<<" p[i].x2 = "<<p[i].x2<<" p[i].y2 = "<<p[i].y2<<endl;
rp(i,1,n)
rp(j,i+1,n)
{
if(p[j].x1 - p[i].x2 > 1 ) break;
if(min(p[i].x2,p[j].x2) - max(p[i].x1,p[j].x1) >= 0 and (p[i].y2 == p[j].y1 - 1 or p[j].y2 == p[i].y1 - 1))
{
if(p[i].y2 == p[j].y1 - 1)
{
ans += (min(p[i].x2,p[j].x2) - max(p[i].x1,p[j].x1)) * 2;
if(p[i].x1 != p[j].x1) ans ++; if(p[i].x2 != p[j].x2) ans ++;
}
if(p[j].y2 == p[i].y1 - 1)
{
ans += (min(p[i].x2,p[j].x2) - max(p[i].x1,p[j].x1)) * 2;
if(p[i].x1 != p[j].x1) ans ++; if(p[i].x2 != p[j].x2) ans ++;
}
}
if(min(p[i].y2,p[j].y2) - max(p[i].y1 ,p[j].y1) >= 0 and (p[i].x2 == p[j].x1 - 1 or p[j].x2 == p[i].x1 - 1))
{
if(p[i].x2 == p[j].x1 - 1)
{
ans += (min(p[i].y2,p[j].y2) - max(p[i].y1,p[j].y1)) * 2;
if(p[i].y1 != p[j].y1) ans ++; if(p[i].y2 != p[j].y2) ans ++;
}
if(p[j].x2 == p[i].x1 - 1)
{
ans += (min(p[i].y2,p[j].y2) - max(p[i].y1,p[j].y1)) * 2;
if(p[i].y1 != p[j].y1) ans ++; if(p[i].y2 != p[j].y2) ans ++;
}
}
if(p[i].x2 == p[j].x1 - 1 and (p[i].y2 == p[j].y1 - 1 or p[i].y1 == p[j].y2 + 1)) ans++;
///cout<<"i = "<<i<<" ans = "<<ans<<endl;
}
cout<<ans<<endl;
return 0;
}
}
signed main() {return xin::main();}
T2:
\(upd\;2021.6.13\)
在经过二逼平衡树的洗礼之后,灵魂得到了升华然后这个题目的思路竟然也毛色吨开(laji谷歌输入法),然后道题目的正解也差不多了:
这个题目其实和二逼平衡树还是很像很像的,都是开很多的 \(splay\) 而不是仅仅一棵,然后再进行统计或者是合并操作。。。
这个题目所要维护的东西还是比较新颖的,将时间作为排序的标准值。。。
然后就可以对于每一个点的信息进行插入,color
time
,还有一些之前 \(splay\) 套路的一些信息。
然后就是用 time
进行排序。。。
就这???
你维护试试,包准没入门
最后进行一遍 \(dfs\),然后进行启发式合并就行了。。。。
简 简 单 单
然后就是 \(code\)
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define debug cout<<"debug"<<endl
#define freopen eat2 = freopen
#define scanf eat1 = scanf
namespace xin_io
{
#define gc() p1 == p2 and (p2 = (p1 = buf) + fread(buf,1,1<<20,stdin),p1 == p2) ? EOF : *p1++
#define scanf eat1 = scanf
#define freopen eat2 = freopen
char buf[1<<20],*p1 = buf,*p2 = buf;FILE *eat2;
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; int eat1;
static const int maxn = 2e6+10,mod = 1e6;
namespace xin
{
class xin_splay{public:int cnt,col,tim,ch[2],val,fa,size;}t[maxn];
class xin_edge{public:int next,ver;}edge[maxn]; int head[maxn],zhi = 0;
int tot,ret;
class xin_splay_tree
{
private:
#define up(x) t[x].size = t[t[x].ch[1]].size + t[t[x].ch[0]].size + 1,t[x].cnt = t[t[x].ch[1]].cnt + t[t[x].ch[0]].cnt + t[x].val
public:
int root; //to distinguish different splay trees
map<int,int>vis; //to record the tim of color
inline int size() {return t[root].size;}
inline void rotate(int x)
{
register int y = t[x].fa,z = t[y].fa;
register int ki = t[y].ch[1] == x;
t[z].ch[t[z].ch[1] == y] = x; t[x].fa = z;
t[y].ch[ki] = t[x].ch[ki xor 1]; t[t[x].ch[ki xor 1]].fa = y;
t[x].ch[ki xor 1] = y; t[y].fa = x;
up(y); up(x);
}//checked
inline void splay(int x,int goal)
{
while(t[x].fa != goal)
{
register int y = t[x].fa, z = t[y].fa;
if(z != goal)
(t[z].ch[0] == y) xor (t[y].ch[0] == x) ? rotate(x) : rotate(y);
rotate(x);
}
up(x);
root = x;
}//checked
inline void insert(int tim,int col,int val)
{
register int now = root,fa = 0;
while(now and tim != t[now].tim) fa = now,now = t[now].ch[tim > t[now].tim];
now = ++tot;
if(fa) t[fa].ch[tim > t[fa].tim] = now;
t[now].cnt = t[now].val = val;
t[now].fa = fa; t[now].tim = tim; t[now].size = 1; t[now].col = col;
splay(now,0);
}//checked
void change(int tim)
{
register int now = root;
while(now and t[now].tim != tim)
now = t[now].ch[tim > t[now].tim];
if(now) t[now].val = 0;
splay(now,0);
}//checked
inline bool judge(int tim,int col)
{
if(!vis[col]) {vis[col] = tim; return true;}
else if(vis[col] > tim) {change(vis[col]);vis[col] = tim; return true;}
else return false;
} //checked
int findx(int x,int lim)
{
if(!x) return 0;
if(t[t[x].ch[0]].size >= lim) findx(t[x].ch[0],lim);
else if(t[t[x].ch[0]].size + 1 >= lim) return ret + t[t[x].ch[0]].cnt + t[x].val;
else ret += t[t[x].ch[0]].cnt + t[x].val,findx(t[x].ch[1],lim -t[t[x].ch[0]].size - 1);
}//checked
int findval(int lim)
{
ret = 0;
if(!lim) return 0;
if(lim >= t[root].size) return t[root].cnt;
int ret = findx(root,lim); return ret;
}//checked
}a[maxn];
int n,m,ans[maxn],k[maxn],rec[maxn]; //rec is to make a node for each splay tree
inline void add(int x,int y) {edge[++zhi].ver = y;edge[zhi].next = head[x]; head[x] = zhi;}
int now;
inline void make(int x)
{
if(!x) return ;
make(t[x].ch[0]);
a[now].insert(t[x].tim,t[x].col,a[now].judge(t[x].tim,t[x].col));
make(t[x].ch[1]);
}
void dfs(int x,int fa)
{
for(register int i=head[x];i;i=edge[i].next)
{
register int y = edge[i].ver;
if(fa == y) continue;
dfs(y,x);
if(a[rec[x]].size() < a[rec[y]].size())
{
// cout<<x<<endl;
now = rec[y];
make(a[rec[x]].root);
rec[x] = now;
}
else
{
now = rec[x];
make(a[rec[y]].root);
// rec[y] = now;
}
}
ans[x] = a[rec[x]].findval(k[x]);
}
inline double time() {return (double)clock()/(double)(CLOCKS_PER_SEC);}
inline short main()
{
#ifndef ONLINE_JUDGE
openfile();
#endif
n = get();
for(register int i=1;i<=n-1;++i)
{
register int x = get(),y = get();
add(x,y); add(y,x);
}
for(register int i=1;i<=n;++i) k[i] = get(),rec[i] = i;
m = get();// time();
for(register int i=1;i<=m;++i)
{
register int x = get(),col = get();
a[rec[x]].insert(i,col,a[rec[x]].judge(i,col));
}
dfs(1,0);
int q = get();
while(q--)
printf("%d\n",ans[get()]);
return 0;
}
}
signed main() {return xin::main();}
T3:
又是 \(dark\) 佬。。。。
设 \(f\) 表示概率,那么我们就可以知道:
。。。。
所以\(code:\)
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
#define int long long
#define debug cout<<"debug"<<endl
#define freopen eat2 = freopen
#define scanf eat1 = scanf
namespace xin_io
{
#define gc() p1 == p2 and (p2 = (p1 = buf) + fread(buf,1,1<<20,stdin),p1 == p2) ? EOF : *p1++
#define scanf eat1 = scanf
#define freopen eat2 = freopen
char buf[1<<20],*p1 = buf,*p2 = buf;FILE *eat2;
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; int eat1;
static const int maxn = 1e5+10,mod = 1000000007;
#include<ctime>
#include<cstring>
namespace xin
{
int n,m,k;
int w[maxn];
inline int ksm(int x,int y,int mod)
{
int ret = 1;
while(y){if(y & 1) ret = ret * x % mod;x = x * x % mod; y >>= 1;}
return ret;
}
inline int inv(int x) {return ksm(x,mod-2,mod);}
int f[maxn],ans,s;
inline short main()
{
#ifndef ONLINE_JUDGE
openfile();
#endif
n = get(); m = get(); k = get();
int day = (n - k + 1) > 0 ? (n - k + 1) : 0;
for(register int i=1;i<=m;++i) w[i] = get();//,w[i] = w[i-1] + w[i];
for(register int i=1;i<=m;++i)
{
s = s + f[i-1] % mod;
f[i] = (ksm(i,k,mod) * inv(ksm(m,k,mod)) - s) % mod;
ans = (ans + w[i] * f[i]) % mod;
}
ans = ans * day % mod;
cout<<ans<<endl;
return 0;
}
}
signed main() {return xin::main();}
T4:
暴搜。。。
只需要考虑每一个起始点和每一个结束点。。。
然后开始暴搜。。。
不需要建边,只要维护一个 \(cost\) 数组就行了。。。
\(cost\) 初始值就设置为 \(0x7f7f7f7f7f\) 就行。。。
最后取得最小值。
一共 \(n <= 12\) ,然而 \(m\) 却$ <=2000$ ,重边很多。。。
之后就有 \(70pts\) 了
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
#define int long long
#define debug cout<<"debug"<<endl
#define freopen eat2 = freopen
#define scanf eat1 = scanf
namespace xin_io
{
#define gc() p1 == p2 and (p2 = (p1 = buf) + fread(buf,1,1<<20,stdin),p1 == p2) ? EOF : *p1++
#define scanf eat1 = scanf
#define freopen eat2 = freopen
char buf[1<<20],*p1 = buf,*p2 = buf;FILE *eat2;
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; int eat1;
static const int maxn = 13;
#include<ctime>
#include<cstring>
#define m(c,num) memset(c,num,sizeof c)
namespace xin
{
int n,m;
int c[maxn][maxn];
int temp;
int num[maxn];
int ans = 0x7f7f7f7f;
void dfs(int now,int cnt)
{
if(cnt == n)
{
ans = min(ans,temp);
return ;
}
if(temp >= ans) return ;
for(register int i=1;i<=n;++i)
if(!num[i])
for(register int j=1;j<=n;++j)
if(c[i][j] != 0x7f7f7f7f and i != j and num[j])
{
temp += num[j] * c[i][j]; num[i] = num[j] + 1;
dfs(i,cnt+1);
temp -= num[j] * c[i][j]; num[i] = 0;
}
}
inline short main()
{
#ifndef ONLINE_JUDGE
openfile();
#endif
n = get(); m = get(); for(register int i=1;i<=n;++i) for(register int j=0;j<=n;++j) c[i][j] = 0x7f7f7f7f;
for(register int i=1;i<=m;++i)
{
register int x = get(),y = get();
c[x][y] = c[y][x] = min(c[x][y],get());
}
for(register int i=1;i<=n;++i)
{num[i] = 1; dfs(i,1); num[i] = 0;}
cout<<ans<<endl;
return 0;
}
}
signed main() {return xin::main();}
之后考虑正解,实际上就是有枝就剪。
然后飞快。。。
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
//#define int long long
#define debug cout<<"debug"<<endl
#define freopen eat2 = freopen
#define scanf eat1 = scanf
#define inf 0x7f7f7f7f
namespace xin_io
{
#define gc() p1 == p2 and (p2 = (p1 = buf) + fread(buf,1,1<<20,stdin),p1 == p2) ? EOF : *p1++
#define scanf eat1 = scanf
#define freopen eat2 = freopen
char buf[1<<20],*p1 = buf,*p2 = buf;FILE *eat2;
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; int eat1;
static const int maxn = 13;
#include<ctime>
#include<cstring>
#define m(c,num) memset(c,num,sizeof c)
namespace xin
{
int n,m;
int vis[maxn],rea[maxn][maxn],tot;
int c[maxn][maxn],d[maxn],l[maxn];
int temp,cnt;
int ans = inf;
inline void dfs(int num,int nd)
{
for(register int i=num;i<=cnt;++i)
{
if(tot + temp * l[vis[i]] >= ans) return;
for(register int j=nd;j<=d[vis[i]];++j)
if(!l[rea[vis[i]][j]])
{
vis[++cnt] = rea[vis[i]][j];
temp -= c[vis[cnt]][rea[vis[cnt]][1]];
tot += c[vis[i]][vis[cnt]] * l[vis[i]];
l[vis[cnt]] = l[vis[i]] + 1;
dfs(i,j+1);
temp += c[vis[cnt]][rea[vis[cnt]][1]];
tot -= c[vis[i]][vis[cnt]] * l[vis[i]];
l[vis[cnt]] = 0;cnt--;
}
nd = 1;
}
if(cnt == n) {ans = min(ans,tot);return ;}
}
int pai;
inline bool comp(int x,int y) {return c[pai][x] < c[pai][y];}
inline short main()
{
#ifndef ONLINE_JUDGE
openfile();
#endif
n = get(); m = get(); for(register int i=1;i<=n;++i) for(register int j=1;j<=n;++j) c[i][j] = inf;
for(register int i=1;i<=m;++i)
{
register int x = get(),y = get(),z = get();
if(z <= c[x][y])
{
if(c[x][y] == inf) rea[x][++d[x]] = y,rea[y][++d[y]] = x;
c[x][y] = c[y][x] = z;
}
}
for(register int i=1;i<=n;++i)
{
pai = i; sort(rea[i]+1,rea[i]+d[i]+1,comp);
temp += c[i][rea[i][1]];
}
for(register int i=1;i<=n;++i)
{
cnt = 1; tot = 0;
temp -= c[i][rea[i][1]];
vis[1] = i;
l[i] = 1;
dfs(1,1);
temp += c[i][rea[i][1]];
l[i] = 0;
}
printf("%d\n",ans);
return 0;
}
}
signed main() {return xin::main();}