A. Balloon Robot

假设机器人$0$时刻位于$0$号位置,那么每个气球所需的时间为$(s_a-b)\bmod m$。

将所有气球按这个时间排序,枚举每个气球的时间作为偏移量,得出最优解即可。

时间复杂度$O(p\log p)$。

  1. #include<cstdio>
  2. #include<algorithm>
  3. using namespace std;
  4. typedef long long ll;
  5. const int N=1000010;
  6. int T,n,m,p,i,s[N];ll f[N],init,ans;
  7. int main(){
  8. scanf("%d",&T);
  9. while(T--){
  10. scanf("%d%d%d",&n,&m,&p);
  11. for(i=1;i<=n;i++)scanf("%d",&s[i]);
  12. init=0;
  13. for(i=1;i<=p;i++){
  14. int a,b;
  15. scanf("%d%d",&a,&b);
  16. f[i]=((s[a]-b)%m+m)%m;
  17. init+=f[i];
  18. }
  19. ans=init;
  20. sort(f+1,f+p+1);
  21. for(i=1;i<=p;i++)ans=min(ans,init-1LL*p*f[i]+1LL*(i-1)*m);
  22. printf("%lld\n",ans);
  23. }
  24. }

  

B. Expected Waiting Time

设$f_n$表示长度为$n$的合法括号序列个数,则奇数为$0$,偶数为卡特兰数。

分母一定是$f_{2n}$,而对于分子,可以考虑每个位置作为左右括号的贡献,假设是第$i$个位置作为左括号,那么枚举与其配对的右括号的距离$j$,则中间的方案数为$f_{j-1}$,剩下部分的方案数为$f_{2n-j-1}$,故总方案数为$\sum_{j=1}^{2n-i}f_{j-1}f_{2n-j-1}$。

注意到$i$只影响上式的求和上界,故直接计算出每个的值即可。

时间复杂度$O(n)$。

  1. #include<cstdio>
  2. typedef long long ll;
  3. const int N=5000000;
  4. int n,P,b,A,B,T,i,a[N],sum,ans;
  5. int h[N],inv[N];
  6. inline ll po(ll a,ll b){
  7. ll t=1;
  8. for(;b;b>>=1,a=a*a%P)if(b&1)t=t*a%P;
  9. return t;
  10. }
  11. inline int C(int n){
  12. if(n&1)return 0;
  13. return h[n>>1];
  14. }
  15. int main(){
  16. scanf("%d",&T);
  17. while(T--){
  18. scanf("%d%d%d%d%d",&n,&P,&b,&A,&B);
  19. h[0]=1;
  20. h[1]=1;
  21. inv[0]=inv[1]=1;
  22. for(i=2;i<=n+1;i++)inv[i]=1LL*(P-inv[P%i])*(P/i)%P;
  23. for(i=2;i<=n;i++)h[i]=1LL*h[i-1]*(i*4-2)%P*inv[i+1]%P;
  24. n*=2;
  25. for(i=1;i<=n;i++){
  26. b=(1LL*b*A+B)%P;
  27. a[i]=(1LL*a[i-1]+1LL*b+1)%P;
  28. }
  29. sum=0;
  30. ans=0;
  31. for(i=1;i<n;i++){
  32. //n-x = i
  33. //x=n-i
  34. sum=(1LL*C(i-1)*C(n-i-1)+sum)%P;
  35. ans=(1LL*(P-a[n-i])*sum+ans)%P;
  36. ans=(1LL*a[i+1]*sum+ans)%P;
  37. }
  38. printf("%d\n",1LL*ans*po(C(n),P-2)%P);
  39. }
  40. }

  

C. Crusaders Quest

爆搜所有可行方案即可。

  1. #include<stdio.h>
  2. #include<iostream>
  3. #include<string.h>
  4. #include<string>
  5. #include<ctype.h>
  6. #include<math.h>
  7. #include<set>
  8. #include<map>
  9. #include<vector>
  10. #include<queue>
  11. #include<bitset>
  12. #include<algorithm>
  13. #include<time.h>
  14. using namespace std;
  15. void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
  16. #define MS(x, y) memset(x, y, sizeof(x))
  17. #define ls o<<1
  18. #define rs o<<1|1
  19. typedef long long LL;
  20. typedef unsigned long long UL;
  21. typedef unsigned int UI;
  22. template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b > a)a = b; }
  23. template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b < a)a = b; }
  24. const int N = 0, M = 0, Z = 1e9 + 7, inf = 0x3f3f3f3f;
  25. template <class T1, class T2>inline void gadd(T1 &a, T2 b) { a = (a + b) % Z; }
  26. int casenum, casei;
  27. char w[4] = "gao";
  28. int p[4];
  29. int ANS;
  30. void dfs(int o, string s, int val)
  31. {
  32. if(o == 2)
  33. {
  34. gmax(ANS, val + 1);
  35. return;
  36. }
  37. int len = s.length();
  38.  
  39. string nxt = "";
  40. for(int j = 0; j < len; ++j)if(s[j] != w[p[o]])nxt = nxt + s[j];
  41.  
  42. bool flag = 0;
  43. for(int i = 0; i < len; ++i)if(s[i] == w[p[o]])
  44. {
  45. flag = (s[i] == s[i + 1] && s[i] == s[i + 2]);
  46. break;
  47. }
  48.  
  49. dfs(o + 1, nxt, val + flag);
  50. }
  51. int main()
  52. {
  53. scanf("%d", &casenum);
  54. for (casei = 1; casei <= casenum; ++casei)
  55. {
  56. string s;
  57. cin >> s;
  58. for(int i = 0; i < 3; ++i)p[i] = i;
  59. ANS = 0;
  60. do
  61. {
  62. dfs(0, s, 0);
  63. }while(next_permutation(p, p + 3));
  64. printf("%d\n", ANS);
  65. }
  66. return 0;
  67. }
  68. /*
  69. 【trick&&吐槽】
  70.  
  71. 【题意】
  72.  
  73. 【分析】
  74.  
  75. 【时间复杂度&&优化】
  76.  
  77. */

  

D. Graph Generator

从后往前还原整个过程。

若图只有一个点,那么方案显然。

若图由多个连通块构成,那么每个连通块之间是独立的,分开处理即可。

否则图只剩下一个大小至少为$2$的连通块,那么最后一步操作必然选择一个到其它每个点都有边的点,然后将图继续分裂成若干连通块。

注意到对于$n$个点的连通块,边数会减少$n-1$,故迭代层数不超过$O(\sqrt{n})$。

时间复杂度$O(n\sqrt{n})$。

  1. #include<cstdio>
  2. #include<vector>
  3. #include<algorithm>
  4. using namespace std;
  5. typedef pair<int,int>P;
  6. const int N=100010,M=200010;
  7. int Case,n,m,i,qa[N],qb[M],tmp[M];
  8. int fin[N];//should reverse
  9. vector<int>ans[N];
  10. int stage;
  11. bool err;
  12. struct E{
  13. int x,y;
  14. }e[M];
  15. int deg[N],g[N],v[M<<1],nxt[M<<1],ed;
  16. int vis[N];
  17. int cnt;
  18. int q[N],cq;
  19. int pos[M];
  20. inline void add(int x,int y){
  21. v[++ed]=y;
  22. nxt[ed]=g[x];
  23. g[x]=ed;
  24. deg[x]++;
  25. }
  26. void dfs(int x){
  27. if(vis[x])return;
  28. vis[x]=cnt;
  29. q[++cq]=x;
  30. for(int i=g[x];i;i=nxt[i])dfs(v[i]);
  31. }
  32. void solve(int nl,int nr,int ml,int mr,vector<int>&old){
  33. if(err)return;
  34. //for(int i=nl;i<=nr;i++)printf("%d ",qa[i]);puts("");
  35. if(nl==nr){
  36. fin[++stage]=qa[nl];
  37. old.push_back(qa[nl]);
  38. return;
  39. }
  40. //find connect comp
  41. int i,j;
  42. cnt=ed=0;
  43. for(i=nl;i<=nr;i++){
  44. int x=qa[i];
  45. deg[x]=g[x]=vis[x]=0;
  46. }
  47. for(i=ml;i<=mr;i++)add(e[qb[i]].x,e[qb[i]].y),add(e[qb[i]].y,e[qb[i]].x);
  48. cq=0;
  49. for(i=nl;i<=nr;i++){
  50. int x=qa[i];
  51. if(!vis[x]){
  52. old.push_back(x);
  53. cnt++;
  54. dfs(x);
  55. }
  56. }
  57. if(cnt==1){
  58. int cv=nr-nl;
  59. for(i=nl;i<=nr;i++)if(deg[qa[i]]==cv)break;
  60. if(i>nr){
  61. err=1;
  62. return;
  63. }
  64. int x=qa[i];
  65. swap(qa[nl],qa[i]);
  66. int L=ml,R=ml-1;
  67. for(i=ml;i<=mr;i++){
  68. int u=e[qb[i]].x,v=e[qb[i]].y;
  69. if(u==x||v==x)continue;
  70. tmp[++R]=qb[i];
  71. }
  72. for(i=L;i<=R;i++)qb[i]=tmp[i];
  73. fin[++stage]=x;
  74. solve(nl+1,nr,L,R,ans[stage]);
  75. }else{
  76. vector<P>nson,mson;
  77. int l=nl;
  78. for(i=1;i<=cq;i=j){
  79. int r=l-1;
  80. for(j=i;j<=cq&&vis[q[i]]==vis[q[j]];j++){
  81. qa[++r]=q[j];
  82. }
  83. nson.push_back(P(l,r));
  84. l=r+1;
  85. }
  86. for(i=1;i<=cnt;i++)pos[i]=0;
  87. pos[0]=ml-1;
  88. for(i=ml;i<=mr;i++)pos[vis[e[qb[i]].x]]++;
  89. for(i=1;i<=cnt;i++)pos[i]+=pos[i-1];
  90. for(i=1;i<=cnt;i++)mson.push_back(P(pos[i-1]+1,pos[i]));
  91. for(i=ml;i<=mr;i++){
  92. int x=vis[e[qb[i]].x];
  93. tmp[pos[x]--]=qb[i];
  94. }
  95. for(i=ml;i<=mr;i++)qb[i]=tmp[i];
  96. int _cnt=cnt;
  97. for(i=0;i<_cnt;i++){
  98. ans[0].clear();
  99. solve(nson[i].first,nson[i].second,mson[i].first,mson[i].second,ans[0]);
  100. }
  101. }
  102. }
  103. int main(){
  104. scanf("%d",&Case);
  105. while(Case--){
  106. scanf("%d%d",&n,&m);
  107. for(i=1;i<=n;i++)qa[i]=i;
  108. for(i=1;i<=m;i++)qb[i]=i;
  109. for(i=1;i<=m;i++)scanf("%d%d",&e[i].x,&e[i].y);
  110. stage=err=0;
  111. for(i=0;i<=n;i++)ans[i].clear();
  112. solve(1,n,1,m,ans[0]);
  113. if(err)puts("No");else{
  114. puts("Yes");
  115. for(i=n;i;i--){
  116. printf("%d %d",fin[i],ans[i].size());
  117. for(int j=0;j<ans[i].size();j++)printf(" %d",ans[i][j]);
  118. puts("");
  119. }
  120. }
  121. }
  122. }

  

E. String of CCPC

设$f[i][j][k]$表示考虑前$i$个字符,目前购买了$j$次,与“CCPC”KMP的指针为$k$的最大净收益。

注意到最优解中$j$为个位数,令其不超过$9$即可。

时间复杂度$O(n)$。

  1. #include<cstdio>
  2. const int N=200010,M=10;
  3. int T,n,m,i,j,k,t,ans,b[N],nxt[N],g[M][2],w[M][2];
  4. int f[N][M][4];
  5. char a[N];
  6. inline void up(int&a,int b){a<b?(a=b):0;}
  7. int main(){
  8. m=4;
  9. b[1]=0;
  10. b[2]=0;
  11. b[3]=1;
  12. b[4]=0;
  13. for(i=2;i<=m;nxt[i++]=j){
  14. while(j&&b[j+1]!=b[i])j=nxt[j];
  15. if(b[j+1]==b[i])j++;
  16. }
  17. for(i=0;i<m;i++){
  18. for(j=0;j<2;j++){
  19. int k=i,o=0;
  20. while(k&&b[k+1]!=j)k=nxt[k];
  21. if(b[k+1]==j)k++;
  22. if(k==m)k=nxt[k],o++;
  23. g[i][j]=k;
  24. w[i][j]=o;
  25. }
  26. }
  27. scanf("%d",&T);
  28. while(T--){
  29. scanf("%d%s",&n,a+1);
  30. for(i=1;i<=n;i++)a[i]=a[i]=='P';
  31. for(i=0;i<=n;i++)for(j=0;j<M;j++)for(k=0;k<m;k++)f[i][j][k]=-10000000;
  32. f[0][0][0]=0;
  33. for(i=0;i<=n;i++)for(j=0;j<M;j++)for(k=0;k<m;k++){
  34. if(j+1<M){
  35. for(t=0;t<2;t++)up(f[i][j+1][g[k][t]],f[i][j][k]+w[k][t]-j);
  36. }
  37. if(i<n)up(f[i+1][j][g[k][a[i+1]]],f[i][j][k]+w[k][a[i+1]]);
  38. }
  39. ans=0;
  40. for(j=0;j<M;j++)for(k=0;k<m;k++)up(ans,f[n][j][k]);
  41. printf("%d\n",ans);
  42. }
  43. }

  

F. Getting Lost

留坑。

G. Numbers

在二进制下从高位到低位贪心考虑。

若答案这一位可以为$0$,那么全部填$0$,否则尽量填$1$。

  1. import java.util.*;
  2.  
  3. import javax.swing.text.TabableView;
  4.  
  5. import java.io.*;
  6. import java.math.*;
  7.  
  8. public class Main
  9. {
  10. static final int N = (int)1e5 + 10;
  11. static Scanner cin = new Scanner(System.in);
  12. static BigInteger v0 = BigInteger.valueOf(0);
  13. static BigInteger v1 = BigInteger.valueOf(1);
  14. static BigInteger v2 = BigInteger.valueOf(2);
  15. static BigInteger b[] = new BigInteger [4000];
  16. public static void main(String args[])
  17. {
  18. b[0] = v1;
  19. for(int i = 1; i < 4000; ++i)b[i] = b[i - 1].multiply(v2);
  20. int casenum = cin.nextInt();
  21. for(int casei = 1; casei <= casenum; ++casei)
  22. {
  23. BigInteger n = cin.nextBigInteger();
  24. BigInteger m = cin.nextBigInteger();
  25. BigInteger top = n.add(m).subtract(v1).divide(m);
  26. int w = 0;
  27. while(b[w].compareTo(top) <= 0)++w;
  28. BigInteger ans = v0;
  29. for(int k = w; k >= 0; --k)
  30. {
  31. if(n.compareTo( b[k].subtract(v1).multiply(m) ) <= 0)
  32. {
  33.  
  34. }
  35. else
  36. {
  37. BigInteger g = n.divide(b[k]);
  38. if(g.compareTo(m) > 0)g = m;
  39. n = n.subtract(g.multiply(b[k]));
  40. ans = ans.add(b[k]);
  41. }
  42. }
  43. System.out.println(ans);
  44. }
  45. }
  46. }

  

H. Prime Set

按奇偶建立二分图匹配模型,先忽略$1$求出最大匹配,再考虑$1$继续求最大匹配,每个匹配都将贡献$2$。

对于剩下的数,再检查能否与已选的数配对,每次配对贡献$1$。

注意特殊处理$1$内部的匹配。

  1. #include<stdio.h>
  2. #include<iostream>
  3. #include<string.h>
  4. #include<string>
  5. #include<ctype.h>
  6. #include<math.h>
  7. #include<set>
  8. #include<map>
  9. #include<vector>
  10. #include<queue>
  11. #include<bitset>
  12. #include<algorithm>
  13. #include<time.h>
  14. using namespace std;
  15. void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
  16. #define MS(x, y) memset(x, y, sizeof(x))
  17. #define ls o<<1
  18. #define rs o<<1|1
  19. typedef long long LL;
  20. typedef unsigned long long UL;
  21. typedef unsigned int UI;
  22. template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b > a)a = b; }
  23. template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b < a)a = b; }
  24. const int N = 3030, M = N * N, Z = 1e9 + 7, inf = 0x3f3f3f3f;
  25. //edge_num = ???
  26. template <class T1, class T2>inline void gadd(T1 &a, T2 b) { a = (a + b) % Z; }
  27. int casenum, casei;
  28. bool is_prime[(int)2e6 + 10];
  29. int nn, K;
  30. int o[N], e[N];
  31.  
  32. int ST, ED, pone;
  33. int first[N], id;
  34. int w[M], cap[M], nxt[M];
  35. void ins(int x, int y, int cap_)
  36. {
  37. w[++id] = y;
  38. cap[id] = cap_;
  39. nxt[id] = first[x];
  40. first[x] = id;
  41. w[++ id] = x;
  42. cap[id] = 0;
  43. nxt[id] = first[y];
  44. first[y] = id;
  45. }
  46.  
  47. int d[N];
  48. bool bfs()
  49. {
  50. //MS(d, -1);
  51. for(int i = 0; i <= ED; ++i)d[i] = -1;
  52. queue<int> q; q.push(ST); d[ST] = 0;
  53. while(! q.empty()){
  54. int x = q.front(); q.pop();
  55. for(int z = first[x]; z; z = nxt[z]) if(cap[z]){
  56. int y = w[z];
  57. if(d[y] == -1){
  58. d[y] = d[x] + 1;
  59. q.push(y);
  60. if(y == ED) return 1;
  61. }
  62. }
  63. }
  64. return 0;
  65. }
  66. int dfs(int x, int all)
  67. {
  68. if(x == ED) return all;
  69. int use = 0;
  70. for(int z = first[x]; z; z = nxt[z] ) if(cap[z]){
  71. int y = w[z];
  72. if(d[y] == d[x] + 1){
  73. int tmp = dfs(y, min(cap[z], all - use));
  74. cap[z] -= tmp;
  75. cap[z ^ 1] += tmp;
  76. use += tmp;
  77. if(use == all) break;
  78. }
  79. }
  80. if(use == 0) d[x] = -1;
  81. return use;
  82. }
  83.  
  84. int dinic()
  85. {
  86. int ret = 0;
  87. while(bfs()) ret += dfs(ST, inf);
  88. return ret;
  89. }
  90.  
  91. void prime_init()
  92. {
  93. int top = 2e6;
  94. MS(is_prime, 1); is_prime[0] = is_prime[1] = 0;
  95. for(int i = 2; i <= top; ++i)if(is_prime[i])
  96. {
  97. for(int j = i + i; j <= top; j += i)
  98. {
  99. is_prime[j] = 0;
  100. }
  101. }
  102. }
  103.  
  104. int main()
  105. {
  106. prime_init();
  107. scanf("%d", &casenum);
  108. for (casei = 1; casei <= casenum; ++casei)
  109. {
  110. scanf("%d%d", &nn, &K);
  111. int odd = 0;
  112. int even = 0;
  113. int one = 0;
  114. for(int i = 1; i <= nn; ++i)
  115. {
  116. int x; scanf("%d", &x);
  117. if(x == 1)++one;
  118. else if(x & 1)o[++odd] = x;
  119. else e[++even] = x;
  120. }o[0] = 1;
  121. pone = 0; ST = odd + even + 1; ED = ST + 1;
  122. for(int i = 0; i <= ED; ++i)first[i] = 0; id = 1;
  123. for(int i = 0; i <= odd; ++i)
  124. {
  125. for(int j = 1; j <= even; ++j)if(is_prime[o[i] + e[j]])
  126. {
  127. ins(i, odd + j, 1);
  128. }
  129. }
  130. for(int i = 1; i <= odd; ++i)ins(ST, i, 1);
  131. for(int i = 1; i <= even; ++i)ins(odd + i, ED, 1);
  132. int ORI_ONE = one;
  133.  
  134. int now = dinic();
  135. //
  136. //printf("two-two pair = %d\n", now);
  137. //
  138. while(one)
  139. {
  140. ins(ST, pone, 1);
  141. if(dinic())
  142. {
  143. ++now;
  144. --one;
  145. }
  146. else break;
  147. }
  148. now += one / 2;
  149. one %= 2;
  150. if(K <= now)
  151. {
  152. printf("%d\n", K * 2);
  153. continue;
  154. }
  155. //K > now
  156. K -= now;
  157.  
  158. int sum = 0;
  159. for(int i = (1 - one); i <= odd; ++i)if(i == 0 || cap[first[i]] == 0)////
  160. {
  161. bool flag = 0;
  162. for(int j = 1; j <= even; ++j)if(is_prime[o[i] + e[j]])
  163. {
  164.  
  165. //
  166. //printf("single odd for even = %d %d\n", o[i], e[j]);
  167. //
  168.  
  169. sum += 1;
  170. flag = 1;
  171. break;
  172. }
  173. if(!flag && i == 0 && ORI_ONE > 1)sum += 1;
  174. }
  175.  
  176. //
  177. //for(int i = 1; i <= even; ++i)printf("cap[%d] = %d\n", e[i], cap[first[odd + i]]);
  178. //
  179.  
  180. for(int i = 1; i <= even; ++i)if(cap[first[odd + i]] == 1)////
  181. {
  182. int st = ORI_ONE ? 0 : 1;
  183. for(int j = st; j <= odd; ++j)if(is_prime[e[i] + o[j]])
  184. {
  185.  
  186. //
  187. //printf("single even for one = %d %d\n", e[i], o[j]);
  188. //
  189.  
  190. sum += 1;
  191. break;
  192. }
  193. }
  194. int ans = now * 2 + min(sum, K);
  195. printf("%d\n", ans);
  196. }
  197. return 0;
  198. }
  199. /*
  200. 【trick&&吐槽】
  201.  
  202. 【题意】
  203.  
  204. 【分析】
  205.  
  206. 【时间复杂度&&优化】
  207. 6 2
  208. 1 1 1 1 2 2
  209. 6 3
  210. 1 1 1 1 2 2
  211.  
  212. 6 2
  213. 1 1 10 10 10 10
  214.  
  215. 7 2
  216. 1 1 1 1 1 2 2
  217.  
  218. 7 3
  219. 1 1 1 1 1 2 2
  220.  
  221. 7 4
  222. 1 1 1 1 1 2 2
  223.  
  224. */

  

I. Triangulation

留坑。

J. Tree Equation

留坑。

K. Diversity and Variance

留坑。

L. One-Dimensional Maze

答案为$\min([2,m]中R的个数,[m,n-1]中L的个数)$。

  1. #include<cstdio>
  2. #include<algorithm>
  3. using namespace std;
  4. const int N=1000010;
  5. int T,n,m,i,A,B;char a[N];
  6. int main(){
  7. scanf("%d",&T);
  8. while(T--){
  9. scanf("%d%d%s",&n,&m,a+1);
  10. A=B=0;
  11. for(i=2;i<=m;i++)if(a[i]=='R')A++;
  12. for(i=m;i<n;i++)if(a[i]=='L')B++;
  13. printf("%d\n",min(A,B));
  14. }
  15. }

  

M. Safest Buildings

下一轮安全区的圆心可行范围可以用圆表示,圆交求出概率即可。

  1. #include<stdio.h>
  2. #include<iostream>
  3. #include<string.h>
  4. #include<string>
  5. #include<ctype.h>
  6. #include<math.h>
  7. #include<set>
  8. #include<map>
  9. #include<vector>
  10. #include<queue>
  11. #include<bitset>
  12. #include<algorithm>
  13. #include<time.h>
  14. using namespace std;
  15. void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
  16. #define MS(x, y) memset(x, y, sizeof(x))
  17. #define ls o<<1
  18. #define rs o<<1|1
  19. typedef long long LL;
  20. typedef unsigned long long UL;
  21. typedef unsigned int UI;
  22. template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b > a)a = b; }
  23. template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b < a)a = b; }
  24. const int N = 0, M = 0, Z = 1e9 + 7, inf = 0x3f3f3f3f;
  25. template <class T1, class T2>inline void gadd(T1 &a, T2 b) { a = (a + b) % Z; }
  26. int casenum, casei;
  27. const double eps = 1e-8, PI = acos(-1.0);
  28.  
  29. struct circle
  30. {
  31. long double x, y, r;
  32. }p1, p2;
  33. long double sqr(long double x)
  34. {
  35. return x * x;
  36. }
  37. long double dis(circle a, circle b)
  38. {
  39. return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y));
  40. }
  41. long double solve(circle a, circle b)
  42. {
  43. long double d = dis(a, b);
  44. if(d >= a.r + b.r) return 0;
  45. if(d <= fabs(a.r - b.r)){
  46. long double r = min(a.r, b.r);
  47. return PI * r * r;
  48. }
  49. long double ang1 = acos((a.r * a.r + d * d - b.r * b.r) / (2. * a.r * d)) * 2;
  50. long double ang2 = acos((b.r * b.r + d * d - a.r * a.r) / (2. * b.r * d)) * 2;
  51. double tmp1 = 0.5 * ang1 * a.r * a.r - 0.5 * a.r * a.r * sin(ang1);
  52. double tmp2 = 0.5 * ang2 * b.r * b.r - 0.5 * b.r * b.r * sin(ang2);
  53. long double ret = tmp1 + tmp2;
  54. return ret;
  55.  
  56. }
  57.  
  58. circle a[110];
  59. int b[110];
  60. double area[110];
  61. int sgn(double x)
  62. {
  63. if(fabs(x) < eps) return 0;
  64. return x > 0 ? 1 : -1;
  65. }
  66.  
  67. int main()
  68. {
  69. double r;
  70. int n;
  71. scanf("%d", &casenum);
  72. for (casei = 1; casei <= casenum; ++casei)
  73. {
  74. double R;
  75. scanf("%d%lf%lf", &n, &R, &r);
  76. a[0].x = 0, a[0].y = 0; a[0].r = R- r;
  77. double ans = 0;
  78. for(int i = 1; i <= n; i ++){
  79. double x, y;
  80. scanf("%lf%lf", &x, &y);
  81. a[i].x = x; a[i].y = y;
  82. a[i].r = r;
  83. area[i] = solve(a[0], a[i]);
  84. gmax(ans, area[i]);
  85. }
  86. int num = 0;
  87. for(int i = 1; i <= n; i ++){
  88. if(sgn(area[i] - ans) == 0){
  89. b[++ num] = i;
  90. }
  91. }
  92. printf("%d\n", num);
  93. for(int i = 1; i < num; i ++) printf("%d ", b[i]); printf("%d\n", b[num]);
  94. }
  95. return 0;
  96. }
  97. /*
  98. 【trick&&吐槽】
  99.  
  100. 【题意】
  101.  
  102. 【分析】
  103.  
  104. 【时间复杂度&&优化】
  105.  
  106. */

  

2017 CCPC Qinhuangdao Site的更多相关文章

  1. 2017 CCPC秦皇岛 A题 A Ballon Robot

    The 2017 China Collegiate Programming Contest Qinhuangdao Site is coming! There will be  teams parti ...

  2. 2017 ccpc哈尔滨 A题 Palindrome

    2017 ccpc哈尔滨 A题 Palindrome 题意: 给一个串\(T\),计算存在多少子串S满足\(S[i]=S[2n−i]=S[2n+i−2](1≤i≤n)\) 思路: 很明显这里的回文串长 ...

  3. HDU 6271 Master of Connected Component(2017 CCPC 杭州 H题,树分块 + 并查集的撤销)

    题目链接  2017 CCPC Hangzhou Problem H 思路:对树进行分块.把第一棵树分成$\sqrt{n}$块,第二棵树也分成$\sqrt{n}$块.    分块的时候满足每个块是一个 ...

  4. HDU 6270 Marriage (2017 CCPC 杭州赛区 G题,生成函数 + 容斥 + 分治NTT)

    题目链接  2017 CCPC Hangzhou Problem G 题意描述很清晰. 考虑每个家庭有且仅有$k$对近亲的方案数: $C(a, k) * C(b, k) * k!$ 那么如果在第$1$ ...

  5. HDU 6240 Server(2017 CCPC哈尔滨站 K题,01分数规划 + 树状数组优化DP)

    题目链接  2017 CCPC Harbin Problem K 题意  给定若干物品,每个物品可以覆盖一个区间.现在要覆盖区间$[1, t]$. 求选出来的物品的$\frac{∑a_{i}}{∑b_ ...

  6. HDU 6268 Master of Subgraph (2017 CCPC 杭州 E题,树分治 + 树上背包)

    题目链接  2017 CCPC Hangzhou  Problem E 题意  给定一棵树,每个点有一个权值,现在我们可以选一些连通的点,并且把这点选出来的点的权值相加,得到一个和. 求$[1, m] ...

  7. 2017 CCPC 哈尔滨站 题解

    题目链接  2017 CCPC Harbin Problem A Problem B Problem D Problem F Problem L 考虑二分答案. 设当前待验证的答案为x 我们可以把第二 ...

  8. 2017 CCPC 杭州 流水账

    day0: 队内训练ccpc 秦皇岛,敝校自己出的题,感觉一个星期没怎么写代码,手生得很,不出意料被打飞了. day1 (热身赛): 热身赛还算顺利,A题看有的队几分钟就草过去了,还以为又是西安ICP ...

  9. 2017 CCPC秦皇岛 E题 String of CCPC

    BaoBao has just found a string  of length  consisting of 'C' and 'P' in his pocket. As a big fan of ...

随机推荐

  1. SQL Server数据库中表的增、删、改

    通过SqlCommand对象的ExecuteNonQuery方法执行命令行,来实现数据库中表的增.删.改.主要有5步 using System.Data.SqlClient;//载入数据库命名空间 p ...

  2. Mycat的分库分表

    其他方法: 雪花算法或者redis来实现id不重复的问题. 数据库分库分表: 垂直拆分的优缺点: 水平拆分: 分片枚举:即根据枚举(定义的常量)进行分类存储.

  3. NLP相关问题中文本数据特征表达初探

    1. NLP问题简介 0x1:NLP问题都包括哪些内涵 人们对真实世界的感知被成为感知世界,而人们用语言表达出自己的感知视为文本数据.那么反过来,NLP,或者更精确地表达为文本挖掘,则是从文本数据出发 ...

  4. 第十三节:Lambda、linq、SQL的相爱相杀(2)

    一. Linq开篇 1.Where用法 linq中where的用法与SQL中where的用法基本一致. #region 01-where用法 { //1. where用法 //1.1 查询账号为adm ...

  5. DataBase vs Data Warehouse

    Database https://en.wikipedia.org/wiki/Database A database is an organized collection of data.[1] A ...

  6. TPS和QPS 并发量区别;日活 访问量 活跃度

    一.系统承载吞度量 系统的吞度量(承压能力)与request对CPU的消耗.外部接口.IO等等紧密关联.单个reqeust 对CPU消耗越高,外部系统接口.IO影响速度越慢,系统吞吐能力越低,反之越高 ...

  7. 支持动态调频_配置AXP228电源管理_4核8核兼容设计_iTOP-4418/6818开发板

    iTOP-4418/6818开发板 支持动态调频,AXP228电源管理, 系统支持:Android4.4/5.1.1.Linux3.4.39.QT2.2/4.7/5.7.Ubuntu12.04 内存: ...

  8. win10安装VMware v14.1.1.28517

    一.下载 VMware v14.1.1.28517 下载地址(包含安装说明):http://www.downza.cn/soft/74728.html 二.VMware Workstation 14 ...

  9. hadoop集群完全分布式搭建

    Hadoop环境搭建:完全分布式 集群规划: ip                 hostname 192.168.204.154     master      namenode   resour ...

  10. rest_framework框架的认识

    它是基于Django的,帮助我们快速开发符合RESTful规范的接口框架. 一  路由 可以通过路由as_view()传参 根据请求方式的不同执行对应不同的方法 在routers模块下 封装了很多关于 ...