\(A,B,C\)顺利签到,还是在\(D\)上面卡住了,之后在睡前还是想出来了,看来还是自己的思维不够敏捷和成熟...

D. Inconvenient Pairs

简化题意,在一个直角坐标系中,有一些横线和竖线,有一些点,都一定在线上,点只能在线上移动。问:有多少个点对满足他们之间的距离大于他们的曼哈顿距离?

首先我们可以将点分为一下类型,点只在横线上(1),点只在竖线上(2),点既在横线上也在竖线上(3)。我们可以发现第3类型的点到任何点的距离都是曼哈顿距离,所以这种类型的点就不予考虑了。同时,发现,只在横线上的点与只在竖线上的点之间的距离也是曼哈顿距离。那吗符合题意的点对一定是只在横线上的点与只在竖线上的点内部之间的点对。考虑两个点\((x_1,y_1)与(x_2,y_2)(假设x_1<x_2)\)他们是两个只在横线上的点。那么他们之间的距离大于马哈顿的距离的条件是所有竖线的\(x\)值要么\(<x1\),要么\(>x2\).也就是在\(x_1-x_2\)之间没有一条竖线。所以我们只根据横线而言,相邻的两条竖线之间我们就可以统计答案,同时会发现可能多个点会在一条横线上,所以答案统计不能简单的相乘,

比如这个图:实际上我们不合法的点对应该是\((1,3),(1,2),(4,3)(4,2)(3,2)\),所以我们可以将两条竖线间的点按照横分组,然后进行统计。这里用到map比较容易实现。

  1. //不等,不问,不犹豫,不回头.
  2. #include<bits/stdc++.h>
  3. #define _ 0
  4. #define ls p<<1
  5. #define db double
  6. #define rs p<<1|1
  7. #define P 1000000007
  8. #define ll long long
  9. #define INF 1000000000
  10. #define get(x) x=read()
  11. #define PLI pair<ll,int>
  12. #define PII pair<int,int>
  13. #define ull unsigned long long
  14. #define put(x) printf("%d\n",x)
  15. #define putl(x) printf("%lld\n",x)
  16. #define rep(x,y,z) for(int x=y;x<=z;++x)
  17. #define fep(x,y,z) for(int x=y;x>=z;--x)
  18. #define go(x) for(int i=link[x],y=a[i].y;i;y=a[i=a[i].next].y)
  19. using namespace std;
  20. const int N=1e6+10;
  21. int n,m,k,heng[N],shu[N],vish[N],viss[N],b1[N],b2[N];
  22. struct dian{int x,y;}a[N];
  23. map<int,int>mp;
  24. inline int read()
  25. {
  26. int x=0,ff=1;
  27. char ch=getchar();
  28. while(!isdigit(ch)) {if(ch=='-') ff=-1;ch=getchar();}
  29. while(isdigit(ch)) {x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
  30. return x*ff;
  31. }
  32. inline bool cmp1(int x,int y) {return a[x].x<a[y].x;}
  33. inline bool cmp2(int x,int y) {return a[x].y<a[y].y;}
  34. int main()
  35. {
  36. //freopen("1.in","r",stdin);
  37. int get(T);
  38. while(T--)
  39. {
  40. get(n);get(m);get(k);
  41. memset(vish,0,sizeof(vish));
  42. memset(viss,0,sizeof(viss));
  43. rep(i,1,n)
  44. {
  45. get(shu[i]);
  46. viss[shu[i]]=1;
  47. }
  48. rep(i,1,m)
  49. {
  50. get(heng[i]);
  51. vish[heng[i]]=1;
  52. }
  53. rep(i,1,k) get(a[i].x),get(a[i].y);
  54. int n1=0,n2=0;
  55. rep(i,1,k)
  56. {
  57. if(vish[a[i].y]&&viss[a[i].x]) continue;
  58. if(vish[a[i].y]) b1[++n1]=i;
  59. else b2[++n2]=i;
  60. }
  61. sort(b1+1,b1+n1+1,cmp1);
  62. sort(b2+1,b2+n2+1,cmp2);
  63. ll ans=0;
  64. int j=1;
  65. rep(i,1,n-1)//统计i和i+1两条竖线之间的点对。
  66. {
  67. int sm=0;
  68. while(j<=n1&&a[b1[j]].x>shu[i]&&a[b1[j]].x<shu[i+1])
  69. {
  70. mp[a[b1[j]].y]++;
  71. sm++;++j;
  72. }
  73. for(auto x:mp)
  74. {
  75. sm-=x.second;
  76. ans+=(ll)x.second*sm;
  77. }
  78. mp.clear();
  79. }
  80. j=1;
  81. rep(i,1,m-1)
  82. {
  83. int sm=0;
  84. while(j<=n2&&a[b2[j]].y>heng[i]&&a[b2[j]].y<heng[i+1])
  85. {
  86. mp[a[b2[j]].x]++;
  87. sm++;++j;
  88. }
  89. for(auto x:mp)
  90. {
  91. sm-=x.second;
  92. ans+=(ll)x.second*sm;
  93. }
  94. mp.clear();
  95. }
  96. putl(ans);
  97. }
  98. return (0^_^0);
  99. }
  100. //以吾之血,铸吾最后的亡魂.

E. Playoff Restoration

关于这个题,感慨是读错题意了,导致怎么想都不对,首先队伍的排列只能是1,2,3,4,5...这样排列,不存在全排列种排列方法,那么剩下的问题就在于每场比赛的胜负问题了。考虑k<=4时,一共进行\(2^{k}-1\)场比赛,最多进行15场比赛我们直接枚举每场比赛的胜负即可。但对于k=5,我们只能进一步思考如何做。

想到比赛的结果是相互独立的,而且k=4可以,而k=5不行,都已经提示的这么明显了,我们可以进行折半搜索。也就是说我们先进行搜索前16个队伍的比赛情况,将所有能得到的h值记录下来。之后在搜索17-32队伍的比赛情况,之后再得到一个h值,然后根据给定的H看是否存在\(h_1+h_2=H\)的情况。即可。

  1. //不等,不问,不犹豫,不回头.
  2. #include<bits/stdc++.h>
  3. #define _ 0
  4. #define ls p<<1
  5. #define db double
  6. #define rs p<<1|1
  7. #define P 998244353
  8. #define ll long long
  9. #define INF 1000000000
  10. #define get(x) x=read()
  11. #define PLI pair<ll,int>
  12. #define PII pair<int,int>
  13. #define ull unsigned long long
  14. #define put(x) printf("%d\n",x)
  15. #define putl(x) printf("%lld\n",x)
  16. #define rep(x,y,z) for(int x=y;x<=z;++x)
  17. #define fep(x,y,z) for(int x=y;x>=z;--x)
  18. #define go(x) for(int i=link[x],y=a[i].y;i;y=a[i=a[i].next].y)
  19. using namespace std;
  20. const int N=100;
  21. ll b[10][N],K,A,H,ars[3],c[N],ID;
  22. ll zw[N];
  23. bool flag=false;
  24. map<ll,bool>mp[2];
  25. inline int read()
  26. {
  27. int x=0,ff=1;
  28. char ch=getchar();
  29. while(!isdigit(ch)) {if(ch=='-') ff=-1;ch=getchar();}
  30. while(isdigit(ch)) {x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
  31. return x*ff;
  32. }
  33. inline ll power(ll x,int y)
  34. {
  35. ll ans=1;
  36. while(y)
  37. {
  38. if(y&1) ans=ans*x%P;
  39. y>>=1;
  40. x=x*x%P;
  41. }
  42. return ans%P;
  43. }
  44. inline void dfs(int n,ll d,int op)
  45. {
  46. if(n==0)
  47. {
  48. if(op==1)
  49. {
  50. ll ans=(d+b[n][1]*power(A,2)%P)%P;
  51. mp[0][ans]=1;
  52. ans=(d+b[n][1]*A%P)%P;
  53. mp[1][ans]=1;
  54. }
  55. else
  56. {
  57. ll ans=(d+b[n][1]*power(A,2))%P;
  58. ll s=(H-ans+P)%P;
  59. if(mp[1].find(s)!=mp[1].end())
  60. {
  61. ars[1]=s;ars[2]=ans;ID=1;
  62. flag=true;return;
  63. }
  64. ans=(d+b[n][1]*A)%P;
  65. s=(H-ans+P)%P;
  66. if(mp[0].find(s)!=mp[0].end())
  67. {
  68. ars[1]=s;ars[2]=ans;ID=2;
  69. flag=true;return;
  70. }
  71. }
  72. return;
  73. }
  74. rep(i,0,(1<<(1<<n-1))-1)//枚举所有的比赛情况
  75. {
  76. ll ans=d;
  77. rep(j,0,(1<<n-1)-1)
  78. {
  79. int x=(j+1)*2-1;
  80. if(i&1<<j)
  81. {
  82. b[n-1][j+1]=b[n][x];
  83. ans=(ans+b[n][x+1]*power(A,(1<<n)+1)%P)%P;
  84. }
  85. else
  86. {
  87. b[n-1][j+1]=b[n][x+1];
  88. ans=(ans+b[n][x]*power(A,(1<<n)+1)%P)%P;
  89. }
  90. }
  91. dfs(n-1,ans,op);
  92. if(flag) return;
  93. }
  94. }
  95. inline void dfs1(int n,ll d,int op)
  96. {
  97. if(n==0)
  98. {
  99. if(ID==1)
  100. {
  101. if(op==1)
  102. {
  103. ll ans=(d+b[n][1]*A%P)%P;
  104. if(ans==ars[op]) {c[b[n][1]]=1;flag=true;return;}
  105. }
  106. else
  107. {
  108. ll ans=(d+b[n][1]*power(A,2)%P)%P;
  109. if(ans==ars[op]) {c[b[n][1]]=2;flag=true;return;}
  110. }
  111. }
  112. else
  113. {
  114. if(op==1)
  115. {
  116. ll ans=(d+b[n][1]*power(A,2)%P)%P;
  117. if(ans==ars[op]) {c[b[n][1]]=2;flag=true;return;}
  118. }
  119. else
  120. {
  121. ll ans=(d+b[n][1]*A%P)%P;
  122. if(ans==ars[op]) {c[b[n][1]]=1;flag=true;return;}
  123. }
  124. }
  125. return;
  126. }
  127. rep(i,0,(1<<(1<<n-1))-1)//枚举所有的比赛情况
  128. {
  129. ll ans=d;
  130. rep(j,0,(1<<n-1)-1)
  131. {
  132. int x=(j+1)*2-1;
  133. if(i&1<<j)
  134. {
  135. b[n-1][j+1]=b[n][x];
  136. c[b[n][x+1]]=(1<<n)+1;
  137. ans=(ans+b[n][x+1]*power(A,(1<<n)+1)%P)%P;
  138. }
  139. else
  140. {
  141. b[n-1][j+1]=b[n][x+1];
  142. c[b[n][x]]=(1<<n)+1;
  143. ans=(ans+b[n][x]*power(A,(1<<n)+1)%P)%P;
  144. }
  145. }
  146. dfs1(n-1,ans,op);
  147. if(flag) return;
  148. }
  149. }
  150. int main()
  151. {
  152. //freopen("1.in","r",stdin);
  153. get(K);get(A);get(H);
  154. if(K==1)
  155. {
  156. if((A+A*A*2)%P==H) printf("%d %d\n",1,2);
  157. else if((A*A+A*2)%P==H) printf("%d %d\n",2,1);
  158. else puts("-1");
  159. return 0;
  160. }
  161. rep(i,1,(1<<K-1)) b[K-1][i]=i;
  162. dfs(K-1,0,1);//K-1为当前剩下的队伍的规模。
  163. rep(i,1,(1<<K-1)) b[K-1][i]=i+(1<<K-1);
  164. dfs(K-1,0,2);
  165. if(!flag) {puts("-1");return 0;}
  166. rep(i,1,(1<<K-1)) b[K-1][i]=i;
  167. flag=false;dfs1(K-1,0,1);
  168. rep(i,1,(1<<K-1)) b[K-1][i]=i+(1<<K-1);
  169. flag=false;dfs1(K-1,0,2);
  170. rep(i,1,1<<K) printf("%lld ",c[i]);
  171. return (0^_^0);
  172. }
  173. //以吾之血,铸吾最后的亡魂.

Educational Codeforces Round 113 (Rated for Div. 2)题解的更多相关文章

  1. Educational Codeforces Round 63 (Rated for Div. 2) 题解

    Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...

  2. Educational Codeforces Round 65 (Rated for Div. 2)题解

    Educational Codeforces Round 65 (Rated for Div. 2)题解 题目链接 A. Telephone Number 水题,代码如下: Code #include ...

  3. Educational Codeforces Round 64 (Rated for Div. 2)题解

    Educational Codeforces Round 64 (Rated for Div. 2)题解 题目链接 A. Inscribed Figures 水题,但是坑了很多人.需要注意以下就是正方 ...

  4. Educational Codeforces Round 60 (Rated for Div. 2) 题解

    Educational Codeforces Round 60 (Rated for Div. 2) 题目链接:https://codeforces.com/contest/1117 A. Best ...

  5. Educational Codeforces Round 58 (Rated for Div. 2) 题解

    Educational Codeforces Round 58 (Rated for Div. 2)  题目总链接:https://codeforces.com/contest/1101 A. Min ...

  6. Educational Codeforces Round 113 (Rated for Div. 2)

    多拿纸画画 ! ! ! Problem - B - Codeforces 题意 给出n个数字(数字为1或2), 1代表这第i个选手没有输过,  2代表这第i个选手至少赢一次 输出为n*n矩阵( i行j ...

  7. Educational Codeforces Round 47 (Rated for Div. 2) 题解

    题目链接:http://codeforces.com/contest/1009 A. Game Shopping 题目: 题意:有n件物品,你又m个钱包,每件物品的价格为ai,每个钱包里的前为bi.你 ...

  8. Educational Codeforces Round 93 (Rated for Div. 2)题解

    A. Bad Triangle 题目:https://codeforces.com/contest/1398/problem/A 题解:一道计算几何题,只要观察数组的第1,2,n个,判断他们能否构成三 ...

  9. Educational Codeforces Round 33 (Rated for Div. 2) 题解

    A.每个状态只有一种后续转移,判断每次转移是否都合法即可. #include <iostream> #include <cstdio> using namespace std; ...

随机推荐

  1. Java比较两个浮点数

    浮点数的基本数据类型不能用==比较,包装数据类型不能用 equals 比较 浮点数的表示 在计算机系统中,浮点数采用 符号+阶码+尾数 进行表示.在Java中,单精度浮点数float类型占32位,它的 ...

  2. 记一次PHP的Invalid binding type问题

    首先说明下环境问题,新旧服务器的迁移.代码在老服务器运行没有任何问题.环境都是PHP7.3,结果新的服务器上流量导过来以后,就报出了如下问题: FastCGI sent in stderr: &quo ...

  3. (原创)一步步优化业务代码之——从数据库获取DataTable并绑定到List<Class>

    一,前言 现实业务当中,有一个很常见的流程:从数据库获取数据到DataTable,然后将DataTable绑定到实体类集合上,一般是List<Class>,代码写起来也简单:遍历+赋值就可 ...

  4. stmt.executeQuery不执行解决办法

    感谢博主分享:https://blog.csdn.net/lxmky/article/details/4705698 今天在Eclipse下编写jsp网页时,出现一个问题,主要是stmt.execut ...

  5. openEuler 20.03/21.03 - 华为欧拉开源版(CentOS 8 华为版开源版)下载

    开始 openEuler 之旅吧 openEuler 通过社区合作,打造创新平台,构建支持多处理架构.统一和开放的操作系统,推动软硬件应用生态繁荣发展. 好玩的活动停不下来 openEuler 社区不 ...

  6. Java中的引用类型和使用场景

    作者:Grey 原文地址:Java中的引用类型和使用场景 Java中的引用类型有哪几种? Java中的引用类型分成强引用, 软引用, 弱引用, 虚引用. 强引用 没有引用指向这个对象,垃圾回收会回收 ...

  7. 服务注册中心之Eureka使用

    一.Eureka基础 Eureka是Netflix开发的服务发现框架,本身是一个基于REST的服务,主要用于定位运行在AWS域中的中间层服务,以达到负载均衡和中间层服务故障转移的目的.SpringCl ...

  8. 极简SpringBoot指南-Chapter05-SpringBoot中的AOP面向切面编程简介

    仓库地址 w4ngzhen/springboot-simple-guide: This is a project that guides SpringBoot users to get started ...

  9. MacOS下Java与JDK关系与相关路径

    MacOS下Java与JDK关系与相关路径 macOS下的Java与JDK的路径曾经困扰过我一段时间,今天稍有些忘记,故记下笔记,整理一下.Java与JDK的关系不在本文笔记之内,Javaer常识. ...

  10. Java初步学习——2021.10.10每日总结,第五周周日

    (1)今天做了什么: (2)明天准备做什么? (3)遇到的问题,如何解决? 今天继续学习菜鸟教程java字符串实例 5.字符串反转--reverse方法 public class Main { pub ...