2019 浙大校赛解题过程及题解

解题过程



 开场lfw看J,被孪生素数误导,没有看出水题的本质,byf及时提醒后,lfw忘记N=1的情况要特判。之后byf写E,忘记开long long,wa+1。Shl看出A题思路,告诉lfw开始写A,lfw忘记先排序,WA+1。byf看出B题做法,lfw写java过掉,shl与lfw讨论G,lfw开始写G,byf看出C可以hash暴力,lfwG忘记清空一个值,导致特殊情况会加两次,wa+1,byf使用mp作hash,带logn常数TLE,随后转成long long的hash值,使用unordered_map过掉。最后lfw和shl讨论出H,lfw开始写H,H没过样例,shl和byf讨论出D题随机,开始上机写D,其中我们都不知道,swap(a[i],a[len-1]).a[i].pop_back()可以删掉vector中的一个元素,百度耗时。最后D题没过,H题没时间调,可惜。
Lfw和byf多次犯小错误,造成罚时很高,而且最后D题写慢,随机没能多交几次,H题没时间调,可惜。


题解



由于刚打完,先附上代码,后面会更新题解。

Thanks, TuSimple!

参考代码:

 1 #include<bits/stdc++.h>
 2 #define maxl 100010
 3 using namespace std;
 4
 5 int n,m,ans;
 6 struct node
 7 {
 8     int h,p;
 9 }a[maxl];
10 int b[maxl];
11 int q[maxl];
12 set <int> s1,s2;
13 set <int> :: iterator it;
14
15 inline void prework()
16 {
17     s1.clear();s2.clear();
18     scanf("%d%d",&n,&m);
19     for(int i=1;i<=n;i++)
20         scanf("%d",&a[i].h);
21     for(int i=1;i<=m;i++)
22         scanf("%d",&b[i]);
23
24     for(int i=1;i<=n;i++)
25         scanf("%d",&a[i].p);
26     for(int i=1;i<=m;i++)
27     {
28         scanf("%d",&q[i]);
29         if(q[i]==0)
30             s1.insert(b[i]);
31         else
32             s2.insert(b[i]);
33     }
34 }
35
36 inline bool cmp(const node &x,const node &y)
37 {
38     return x.h<y.h;
39 }
40
41 inline void mainwork()
42 {
43     sort(a+1,a+1+n,cmp);
44     ans=0;
45     for(int i=1;i<=n;i++)
46     if(a[i].p==0)
47     {
48         it=s2.begin();
49         if(it!=s2.end())
50             if((*it)<a[i].h)
51             {
52                 ans++;
53                 s2.erase(it);
54             }
55     }
56     else
57     {
58         it=s1.upper_bound(a[i].h);
59         if(it!=s1.end())
60             if((*it)>a[i].h)
61             {
62                 ans++;
63                 s1.erase(it);
64             }
65     }
66 }
67
68 inline void print()
69 {
70     printf("%d\n",ans);
71 }
72
73 int main()
74 {
75     int t;
76     scanf("%d",&t);
77     for(int i=1;i<=t;i++)
78     {
79         prework();
80         mainwork();
81         print();
82     }
83     return 0;
84 }

B.Even Number Theory

参考代码:

 1 import java.util.Scanner;
 2 import java.math.*;
 3 import java.text.*;
 4
 5 public class Main {
 6     public static void main(String args[])
 7     {
 8         Scanner input=new Scanner(System.in);
 9         int t;
10         BigInteger e,ans,zero=BigInteger.valueOf(0);
11         BigInteger two=BigInteger.valueOf(2);
12         t=input.nextInt();
13         for(int i=1;i<=t;i++)
14         {
15             e=input.nextBigInteger();
16             e=e.divide(two);ans=BigInteger.valueOf(0);
17             while(!(e.equals(zero)))
18             {
19                 ans=ans.add(e);
20                 e=e.divide(two);
21
22             }
23             System.out.println(ans);
24         }
25     }
26 }

C. Robot Cleaner I

参考代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef pair<int,int> pii;
 4 typedef long long LL;
 5 unordered_map<LL,bool> vis;
 6 char s[255];
 7 char lin[2005];
 8 int mp[2005][2005];
 9 int t4=3*3*3*3,t3=3*3*3,t2=3*3,t1=3;
10 int calc(int i,int j)
11 {
12     return 1+t4*mp[i][j]+t3*mp[i-1][j]+t2*mp[i+1][j]+t1*mp[i][j-1]+mp[i][j+1];
13 }
14 bool check(int x,int y)
15 {
16     if(mp[x][y]!=1) return true;
17     return false;
18 }
19 int zo2=2000*2000,zo1=2000;
20 LL Hash(int x,int y,int cnt)
21 {
22     return 1LL*zo2*(x-1)+1LL*zo1*(y-1)+cnt-1;
23 }
24 int main()
25 {
26     int t;
27     scanf("%d",&t);
28     while(t--)
29     {
30         vis.clear();
31         int n,m;
32         scanf("%d%d",&n,&m);
33         int a,b;
34         LL k;
35         scanf("%d%d%lld",&a,&b,&k);
36         scanf("%s",s+1);
37         int cnt=0;
38         for(int i=1;i<=n;i++)
39         {
40             scanf("%s",lin+1);
41             for(int j=1;j<=m;j++)
42             {
43                 mp[i][j]=lin[j]-‘0‘;
44                 if(mp[i][j]==2) cnt++;
45             }
46         }
47         int ans=0;
48         pii loc=pii(a,b);
49         int mov;
50         char op;
51         int x,y;
52         LL tim=0;
53         while(++tim<=k)
54         {
55             mov=calc(loc.first,loc.second);
56             op=s[mov];
57             if(vis.count(Hash(loc.first,loc.second,cnt))) break;
58             vis[Hash(loc.first,loc.second,cnt)]=1;
59             x=loc.first,y=loc.second;
60             if(op==‘U‘) if(check(x-1,y)) loc=pii(x-1,y);
61             if(op==‘D‘) if(check(x+1,y)) loc=pii(x+1,y);
62             if(op==‘L‘) if(check(x,y-1)) loc=pii(x,y-1);
63             if(op==‘R‘) if(check(x,y+1)) loc=pii(x,y+1);
64             if(op==‘P‘) if(mp[x][y]==2)mp[x][y]=0,ans++,cnt--;
65         }
66         printf("%d\n",ans);
67     }
68 }

D.Robot Cleaner II

Unsolved.

E.Potion

参考代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 LL a[105],b[105];
 5 int main()
 6 {
 7     int t;
 8     scanf("%d",&t);
 9     while(t--)
10     {
11         int n;
12         scanf("%d",&n);
13         for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
14         for(int i=1;i<=n;i++) scanf("%lld",&b[i]);
15         LL las=0;
16         bool flag=1;
17         for(int i=n;i>=1;i--)
18         {
19             if(las+b[i]>=a[i])
20             {
21                 las=las+b[i]-a[i];
22             }
23             else
24             {
25                 flag=0;
26                 break;
27             }
28         }
29         if(flag)
30         {
31             puts("Yes");
32         }
33         else puts("No");
34     }
35 }

F.Strange Function

Unsolved.

G.Postman

参考代码:

 1 #include<bits/stdc++.h>
 2 #define maxl 100010
 3
 4 using namespace std;
 5
 6 int n,k,suml,sumr;
 7 int lcnt[maxl],rcnt[maxl];
 8 long long ans;
 9 long long a[maxl],sum[maxl];
10 long long lnum[maxl],rnum[maxl];
11
12 inline void prework()
13 {
14     scanf("%d%d",&n,&k);
15     for(int i=1;i<=n;i++)
16         scanf("%lld",&a[i]);
17     sort(a+1,a+1+n);
18 }
19
20 inline void mainwork()
21 {
22     int lind=0,rind=n+1;
23     for(int i=1;i<=n;i++)
24     if(a[i]<0)
25         lind=i;
26     suml=0;sumr=0;
27     for(int i=1;i<=lind;i++)
28     if(a[i]!=lnum[suml])
29         lnum[++suml]=a[i],lcnt[suml]=1;
30     else
31         lcnt[suml]++;
32     for(int i=1;i<=n;i++)
33     if(a[i]>0)
34     {
35         rind=i;
36         break;
37     }
38     for(int i=rind;i<=n;i++)
39     if(a[i]!=rnum[sumr])
40         rnum[++sumr]=a[i],rcnt[sumr]=1;
41     else
42         rcnt[sumr]++;
43     int tmp=0;
44     long long sum=0,last;
45     for(int i=1;i<=n;i++)
46     {
47         if(a[i]>=0)
48             break;
49         if(tmp==0)
50             last=-a[i];
51         tmp++;
52         if(tmp==k)
53             sum+=2ll*last,tmp=0,last=0;
54     }
55     sum+=2ll*last;last=0;
56     tmp=0;
57     for(int i=n;i>=1;i--)
58     {
59         if(a[i]<=0)
60             break;
61         if(tmp==0) last=a[i];
62         tmp++;
63         if(tmp==k)
64             sum+=2ll*last,tmp=0,last=0;
65     }
66     sum+=2ll*last;last=0;
67     if(a[1]>=0 && a[n]>0)
68         ans=sum-a[n];
69     else
70     if(a[n]<=0 && a[1]<0)
71         ans=sum-(-a[1]);
72     else
73     if(a[1]<0 && a[n]>0)
74         ans=min(sum-a[n],sum-(-a[1]));
75     else
76         ans=0;
77 }
78
79 inline void print()
80 {
81     printf("%lld\n",ans);
82 }
83
84 int main()
85 {
86     int t;
87     scanf("%d",&t);
88     for(int i=1;i<=t;i++)
89     {
90         prework();
91         mainwork();
92         print();
93     }
94     return 0;
95 }

H.Rescue the Princess

参考代码:

  1 #include<bits/stdc++.h>
  2 using namespace std;
  3 const int N=2e5+10;
  4 struct Edge{
  5     int go,next,x;
  6 }e[2*N],e2[2*N];
  7 int head[N],tot,h[N],t2;
  8 void add(int x,int y){
  9     e[++tot].go=y;
 10     e[tot].x=x;
 11     e[tot].next=head[x];
 12     head[x]=tot;
 13 }
 14 void a2(int x,int y){
 15     e2[++t2].go=y;
 16     e2[t2].next=h[x];
 17     h[x]=t2;
 18 }
 19 int sta[N],be[N],top,dfn[N],low[N],ind,vis[N],cnt;
 20 void tarjan(int x,int f){
 21     dfn[x]=low[x]=++ind;
 22     sta[++top]=x;
 23     bool fir=1;
 24     for(int i=head[x];i;i=e[i].next){
 25         int v=e[i].go;
 26         if(v==f&&fir){
 27             fir=0;
 28             continue;
 29         }
 30         if(!dfn[v]){
 31             tarjan(v,x);
 32             low[x]=min(low[x],low[v]);
 33         }
 34         else if(!vis[v])low[x]=min(low[x],low[v]);
 35     }
 36     if(low[x]==dfn[x]){
 37         be[x]=++cnt;vis[x]=1;
 38         while(sta[top]!=x){
 39             int t=sta[top--];
 40             be[t]=cnt;
 41             vis[t]=1;
 42         }
 43         top--;
 44     }
 45 }
 46 int n,m,q;
 47 int ind2,df[2*N],p[2*N],st[2*N][20],dep[N];
 48 void dfs(int x,int f){
 49     df[x]=++ind2;
 50     dep[x]=dep[f]+1;
 51     p[ind2]=x;
 52     for(int i=h[x];i;i=e2[i].next){
 53         int v=e2[i].go;
 54         if(v==f)continue;
 55         dfs(v,x);
 56         p[++ind2]=x;
 57     }
 58 }
 59 void ini(){
 60     for(int i=1;i<=ind2;i++)st[i][0]=df[p[i]];
 61     for(int i=1;i<=19;i++){
 62         for(int j=1;j+(1<<i)-1<=ind2;j++){
 63             st[j][i]=min(st[j][i-1],st[j+(1<<(i-1))][i-1]);
 64         }
 65     }
 66 }
 67 int lca(int x,int y){
 68     x=df[x],y=df[y];
 69     if(x>y)swap(x,y);
 70     int k=log2(y-x+1);
 71     int t=min(st[x][k],st[y-(1<<k)+1][k]);
 72     return p[t];
 73 }
 74 int a[N];
 75 int fin(int &x){
 76     if(x!=a[x])return x=fin(a[x]);
 77     return x;
 78 }
 79 void merg(int x,int y){
 80     fin(x);fin(y);
 81     a[x]=y;
 82 }
 83 bool ck(int x,int y,int z){
 84     fin(x);fin(y);fin(z);
 85     return x==y&&y==z;
 86 }
 87 inline void init(){
 88     tot=t2=ind=cnt=top=ind2=0;
 89     for(int i=1;i<=n;i++){
 90         head[i]=h[i]=0;
 91         vis[i]=be[i]=0;
 92         dfn[i]=low[i]=0;
 93         dep[i]=0;
 94         a[i]=i;
 95     }
 96 }
 97 int inline dis(int x,int y){
 98     int k=lca(x,y);
 99     return dep[x]+dep[y]-2*dep[k];
100 }
101 int main(){
102     int T;
103     scanf("%d",&T);
104     while(T--){
105         scanf("%d%d%d",&n,&m,&q);
106         init();
107         int ch=0;
108         for(int i=1;i<=m;i++){
109             int x,y;
110             scanf("%d%d",&x,&y);
111             if(x==y){
112                 ch++;
113                 continue;
114             }
115             add(x,y);add(y,x);
116             merg(x,y);
117         }
118         for(int i=1;i<=n;i++){
119             if(!dfn[i])tarjan(i,0);
120         }
121         for(int i=1;i<=2*m-2*ch;i++){
122             int x=e[i].x,y=e[i].go;
123             if(be[x]!=be[y]){
124                 a2(be[x],be[y]);
125             }
126         }
127         for(int i=1;i<=cnt;i++){
128             if(!dep[i])dfs(i,0);
129         }
130         ini();
131         for(int i=1;i<=q;i++){
132             int u,v,w;
133             scanf("%d%d%d",&u,&v,&w);
134             if(!ck(u,v,w))puts("No");
135             else {
136                 u=be[u];v=be[v];w=be[w];
137                 if(dis(u,v)+dis(u,w)==dis(v,w))puts("Yes");
138                 else puts("No");
139             }
140         }
141     }
142     return 0;
143 }

I.Defense Plan

参考代码:

 1 #include<bits/stdc++.h>
 2
 3 using namespace std;
 4
 5 int main()
 6 {
 7     int t;long long n;
 8     scanf("%d",&t);
 9     for(int i=1;i<=t;i++)
10     {
11         scanf("%lld",&n);
12         if(n==1)
13             puts("8 9");
14         else
15             printf("%lld %lld\n",2*n,3*n);
16     }
17     return 0;
18 }

原文地址:https://www.cnblogs.com/songorz/p/10708269.html

时间: 2024-08-26 22:02:39

2019 浙大校赛解题过程及题解的相关文章

2019浙大校赛--J--Extended Twin Composite Number(毒瘤水题)

毒瘤出题人,坑了我们好久,从基本的素数筛选,到埃氏筛法,到随机数快速素数判定,到费马小定理,好好的水题做成了数论题. 结果答案是 2*n=n+3*n,特判1,2. 以下为毒瘤题目: 题目大意: 输入一个数n, 输出两个合数(即非素数)a,b 实现 n+a=b 解题思路 3n=n+2n; 特判1.2 代码: 1 #include<iostream> 2 #include<stdio.h> 3 using namespace std; 4 typedef long long ll; 5

2019 ICPC南昌邀请赛比赛过程及题解

解题过程 中午吃饭比较晚,到机房lfw开始发各队的账号密码,byf开始读D题,shl电脑卡的要死,启动中...然后听到谁说A题过了好多,然后shl让blf读A题,A题blf一下就A了.然后lfw读完M题(shl的电脑终于打开了,然后输入密码,密码错误...自闭),说AC 自动机板题,然后找板子,,,突然发现自己读错题目.后来不知道怎么A的.shl copy了一遍密码终于登上账号.然后lfw一个人用单调栈A掉了I题:byf 秒了H题: shl和byf读j题,读完吧题意告诉lfw,lfw说水题,然后

2014哈商大ICPC/ACM校赛解题报告

被debug邀请去參加校赛,哎,被虐..我对不起工大.. 由于本人不搞ACM,算法处于HelloWorld水准.. 虽然题目除了鸟不拉屎星人之外都非常水,但我能做到这个程度,全然是超水平发挥了.. 数据:点此下载 ============================================================== a:逆序数组+删除特定元素 题目: 小伙伴们好像非常多没接触过ICPC,那先来一道水题尝尝鲜,给出 一个数组,和一个特征值.将这个数组中特征值值删除后逆序输出.

15th浙大校赛 zoj3860-3868

比赛链接: here 题目对应到ZOJ3860~3868 A Find the Spy 水 #include<cstdio> #include<map> #include<cstring> #include<iostream> using namespace std; map<int,int>mp; map<int,int>::iterator it; int main() { int T,n,x; scanf("%d&qu

ZOJ 3866 Cylinder Candy (浙大校赛+积分应用)

题目链接:ZOJ 3866 Cylinder Candy 题意:抽象出来就是求一个圆柱体外面加一层厚度为d的巧克力,求包装完这个立体图形的体积和表面积. 剖析: 以下是包装后的三视图: 图3 接下里就是积分了 2*V1是图3绕y轴的体积 V2是中间的半径为(r+d)的圆柱体积 S1是中间的半径为(r+d)的圆柱的表面积 S2是上下两个半径为r的圆的面积 S3是图3绕y轴的侧面积 附上旋转体的侧面积和体积求法: AC代码: #include <stdio.h> #include <math

2017 浙大校赛 [Cloned]

https://vjudge.net/contest/285902#overview A.Marjar Cola #include <bits/stdc++.h> using namespace std; int T; int main() { scanf("%d", &T); while(T --) { int x, y, a, b; int ans = 0; scanf("%d%d%d%d", &x, &y, &a,

[水]浙大校赛补题

本来以为会巨难无比又有别的比赛可以打于是赛后补题,结果发现似乎略水,反正是找到了四个水题先贴下来 ZOJ-4099 J #include<iostream> #include<cstdio> #include<algorithm> using namespace std; typedef long long ll; int t; ll x, y, n; int main() { cin >> t; while (t--) { scanf("%lld

2019湘潭校赛 G(并查集)

要点 题目传送 题目本质是每个点必属于两个集合中的一个,伴随的性质是:如果一个人说别人true,则他们一定属于同一阵营:如果说别人fake,一定不属于同一阵营. 每个点拆为\(i\)和\(i + n\)分别代表他属于某种阵营(目前还不确定),然后根据上述性质边读入边合并同类. 这样扫一遍,如果某个\(i\)和\(i + n\)属于同一阵营则矛盾,无解. 若有解,对于每个点扫一遍和他同阵营的人,为了使fakeman尽可能地少,\(<=n\)的人少就把\(<=n\)视为fakeman:否则把\(&

2016 SCNUCPC 校赛非官方题解

我要举报本次校赛出题人的消极出题!!! A. 树链剖分数据结构板题 B. The background of water problem 题目大意(大写加粗的水题):给定$N$个学生和他们$K$个科目的成绩$S_i$,再给出各科目$K_i$的权重顺序$Q_i$,求排名之后,拥有id为$X$的是哪个学生. 基本思路:虽然$K$只有$10$,$S$只有$100$,但有M组查询,所以当然不能开个long long去hash每个学生.我们简单点,开个结构体,排个序,就好了. 参考代码: 官方代码(将成绩