A. Add and Reverse

要么全部都选择$+1$,要么加出高$16$位后翻转位序然后再补充低$16$位。

  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() { }
  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 = 1<<16, 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. LL n;
  28. int f[N];
  29. int main()
  30. {
  31. scanf("%lld",&n);
  32. LL A=n>>16;
  33. LL B=n&65535;
  34. LL ans=B;
  35. if(A)ans++;
  36. for(LL i=0;i<16;i++)if(A>>(15-i)&1)ans+=1LL<<i;
  37. printf("%lld",min(ans,n));
  38. return 0;
  39. if(0)while(~scanf("%lld",&n))
  40. {
  41. LL top = 1ll << 32;
  42. LL i = n;
  43. LL w =
  44. printf("%lld\n", w);
  45. }
  46. //return 0;
  47. {
  48. MS(f, 63);
  49. f[0] = 0;
  50. queue<int>q;
  51. q.push(0);
  52. int top = 1ll << 16;
  53. while(!q.empty())
  54. {
  55. int x = q.front(); q.pop();
  56. int y = x + 1;
  57. if(y <= top && f[x] + 1 < f[y])
  58. {
  59. f[y] = f[x] + 1;
  60. q.push(y);
  61. }
  62. int z = top - x;
  63. if(f[x] + 1 < f[z])
  64. {
  65. f[z] = f[x] + 1;
  66. q.push(y);
  67. }
  68. }
  69. for(int i = 0; i < top; ++i)
  70. {
  71. int w = i <= top / 2 ? i : top + 1 - i;
  72. printf("%d: %d %d\n", i, f[i], w);
  73. if(w != f[i])
  74. {
  75. puts("no!!!");
  76. while(1);
  77. }
  78. }
  79. }
  80. return 0;
  81. }
  82.  
  83. /*
  84. 【trick&&吐槽】
  85.  
  86. 【题意】
  87.  
  88. 【分析】
  89.  
  90. 【时间复杂度&&优化】
  91.  
  92. */

  

B. Analyze This

bitset加速暴力。

  1. #include<cstdio>
  2. const int N=400010;
  3. int n,m,mx,lim,i,j,x,a[N],f[N][2];unsigned long long v[64][N/64+5];
  4. inline void solve(int d){
  5. int i,j,A=d>>6,B=d&63;
  6. for(i=0;i+A<=lim;i++)if(v[0][i]&v[B][i+A])for(j=i<<6;;j++)if(a[j]&&a[j+d]){
  7. f[d][0]=a[j];
  8. f[d][1]=a[j+d];
  9. return;
  10. }
  11. }
  12. int main(){
  13. scanf("%d%d",&n,&m);
  14. for(i=1;i<=n;i++){
  15. scanf("%d",&x);
  16. a[x]=i;
  17. if(x>mx)mx=x;
  18. }
  19. lim=mx/64;
  20. for(i=0;i<=mx;i++)if(a[i])for(j=0;j<64&&j<=i;j++)v[j][(i-j)>>6]|=1ULL<<((i-j)&63);
  21. for(f[0][1]=i=1;i<=mx;i++){
  22. f[i][0]=f[i-1][0];
  23. f[i][1]=f[i-1][1];
  24. solve(i);
  25. }
  26. while(m--){
  27. scanf("%d",&x);
  28. if(x>mx)x=mx;
  29. printf("%d %d\n",f[x][0],f[x][1]);
  30. }
  31. }

  

C. Bipartite Graph

每个点向附近$3$个点连边即可。

  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() { }
  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. int T;
  28. int main()
  29. {
  30. scanf("%d",&T);
  31. while(T--)
  32. {
  33. int n; scanf("%d", &n);
  34. printf("%d\n", (n - 2) * 3);
  35. for(int d = 0; d <= 2; ++d)
  36. {
  37. for(int i = 0; i < n - 2; ++i)
  38. {
  39. printf("%d %d\n", d + i, i);
  40. }
  41. }
  42. }
  43. return 0;
  44. }
  45.  
  46. /*
  47. 【trick&&吐槽】
  48.  
  49. 【题意】
  50.  
  51. 【分析】
  52.  
  53. 【时间复杂度&&优化】
  54.  
  55. */

  

D. Bridge Building

二分答案,那么对于$x$个物品$a$,$y$的数量是定的,设$f[i][j]$表示$i$个$a$和$j$个$b$最多拼出几列,按性价比从小到大背包,一旦有解则返回。

时间复杂度$O(n^3\log n)$。

  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. const int N=505;
  16. int X,A,Y,B,L,mid,f[N][N];
  17. inline void up(int&a,int b){a<b?(a=b):0;}
  18. pair<int,int>a[N];
  19. bool cmp(pair<int,int> a, pair<int,int> b)
  20. {
  21. int val1 = a.first * A + a.second * B;
  22. int val2 = b.first * A + b.second * B;
  23. return val1 < val2;
  24. }
  25. inline bool check(){
  26. int i,j,k;
  27. for(i=0;i<=X;i++)for(j=0;j<=Y;j++)f[i][j]=0;
  28.  
  29. int g = 0;
  30. int pre=10000000;
  31. for(i=0;i<=X;i++){
  32. //A*i+B*j>=mid
  33. int ret=mid-A*i;
  34. int tmp=0;
  35. if(ret>0)tmp=ret/B+((ret%B)>0);
  36. if(tmp>=pre)continue;
  37. pre=tmp;
  38. if(tmp>Y)continue;
  39. a[++g].first = i; a[g].second = tmp;
  40. if(ret <= 0)break;
  41. }
  42. //x++, y--
  43.  
  44. /*
  45. for(int j = X; j >= 0; --j)
  46. {
  47. for(int k = Y; k >= 0; --k)
  48. {
  49. int st = g + 1;
  50. int l = 1;
  51. int r = g;
  52. while(l <= r)
  53. {
  54. int mid = (l+r)/2;
  55. if(a[mid].second <= k)
  56. {
  57. st = mid;
  58. r = mid - 1;
  59. }
  60. else l = mid + 1;
  61. }
  62. if(st > g || a[st].first > j)break;
  63. if(f[j][k] >= L - 1)return 1;
  64. for(int i = st; i <= g && a[i].first <= j; ++i)
  65. {
  66. up(f[j - a[i].first][k - a[i].second], f[j][k] + 1);
  67. }
  68. }
  69. }
  70. */
  71.  
  72. sort(a + 1, a + g + 1, cmp);
  73.  
  74. for(int o=1;o<=g;++o){
  75.  
  76. int i = a[o].first;
  77. int tmp = a[o].second;
  78.  
  79. for(j=X;j>=i;j--)for(k=Y;k>=tmp;k--){
  80. if(f[j][k]>=L-1)return 1;
  81. up(f[j-i][k-tmp],f[j][k]+1);
  82. }
  83. }
  84. //for(i=0;i<=X;i++)for(j=0;j<=Y;j++)if(f[i][j]>=L)return 1;
  85.  
  86. return 0;
  87. }
  88. int main(){
  89. while(~scanf("%d%d%d%d%d",&X,&A,&Y,&B,&L)){
  90. int l=1,r=(A*X+Y*B)/L,ans=0;
  91. while(l<=r){
  92. mid=(l+r)>>1;
  93. if(check())l=(ans=mid)+1;else r=mid-1;
  94. }
  95. printf("%d\n",ans);
  96. }
  97. }
  98. /*
  99. 1 1 1 1 1
  100. */

  

E. Child’s Game with Robot

顺时针走一圈,若目的地在中心则回来,否则在目的地两侧来回挪动,若奇偶性不同则原地不动一次进行调整。

  1. #include<cstdio>
  2. int movenorth(){//founded?
  3. puts("move north");
  4. fflush(stdout);
  5. char s[100];
  6. scanf("%s",s);
  7. return s[0]=='f';
  8. }
  9. int movewest(){//founded?
  10. puts("move west");
  11. fflush(stdout);
  12. char s[100];
  13. scanf("%s",s);
  14. return s[0]=='f';
  15. }
  16. int moveeast(){//founded?
  17. puts("move east");
  18. fflush(stdout);
  19. char s[100];
  20. scanf("%s",s);
  21. return s[0]=='f';
  22. }
  23. int movesouth(){//founded?
  24. puts("move south");
  25. fflush(stdout);
  26. char s[100];
  27. scanf("%s",s);
  28. return s[0]=='f';
  29. }
  30. int stay(){//founded?
  31. puts("echo Ready!");
  32. fflush(stdout);
  33. char s[100];
  34. scanf("%s",s);
  35. return s[0]=='f';
  36. }
  37. int main(){
  38. if(movenorth()){
  39. stay();
  40. for(int i=1;i<=4;i++){
  41. movesouth();
  42. movenorth();
  43. }
  44. return 0;
  45. }
  46. if(movewest()){
  47. for(int i=1;i<=4;i++){
  48. moveeast();
  49. movewest();
  50. }
  51. return 0;
  52. }
  53. if(movesouth()){
  54. stay();
  55. for(int i=1;i<=3;i++){
  56. movesouth();
  57. movenorth();
  58. }
  59. return 0;
  60. }
  61. if(movesouth()){
  62. for(int i=1;i<=3;i++){
  63. movenorth();
  64. movesouth();
  65. }
  66. return 0;
  67. }
  68. if(moveeast()){
  69. stay();
  70. for(int i=1;i<=2;i++){
  71. movenorth();
  72. movesouth();
  73. }
  74. return 0;
  75. }
  76. if(moveeast()){
  77. for(int i=1;i<=2;i++){
  78. movenorth();
  79. movesouth();
  80. }
  81. return 0;
  82. }
  83. if(movenorth()){
  84. stay();
  85. movenorth();
  86. movesouth();
  87. return 0;
  88. }
  89. if(movenorth()){
  90. movesouth();
  91. movenorth();
  92. return 0;
  93. }
  94. movesouth();
  95. movewest();
  96. return 0;
  97. }

  

F. Quadruples of Points

给每个集合一个unsigned long long的随机权值,扫描线+树状数组查询矩形内所有点的权值和即可。

  1. #include<cstdio>
  2. #include<algorithm>
  3. using namespace std;
  4. typedef unsigned long long ll;
  5. const int N=2000010;
  6. ll ran,goal;
  7. int n,m,i,j,ce;
  8. int a[N],cnt;
  9. ll bit[N],ans[N];
  10. struct P{
  11. int x,l,r,t;ll v;
  12. P(){}
  13. P(int _x,int _l,int _r,int _t,ll _v){x=_x,l=_l,r=_r,t=_t,v=_v;}
  14. }e[N];
  15. inline bool cmp(const P&a,const P&b){
  16. return a.x!=b.x?a.x<b.x:a.t<b.t;
  17. }
  18. inline void ins(int x,ll p){for(;x<=cnt;x+=x&-x)bit[x]+=p;}
  19. inline ll ask(int x){ll t=0;for(;x;x-=x&-x)t+=bit[x];return t;}
  20. inline ll sum(int l,int r){return ask(r)-ask(l-1);}
  21. int main(){
  22. scanf("%d%d",&n,&m);
  23. for(i=1;i<=n;i++){
  24. ran=ran*233+17;
  25. goal+=ran;
  26. goal+=ran;
  27. for(j=0;j<4;j++){
  28. int x,y;
  29. scanf("%d%d",&x,&y);
  30. e[++ce]=P(x,y,0,0,ran);
  31. a[++cnt]=y;
  32. }
  33. }
  34. for(i=1;i<=m;i++){
  35. int x1,y1,x2,y2;
  36. scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
  37. e[++ce]=P(x2,y1,y2,1,i);
  38. e[++ce]=P(x1-1,y1,y2,2,i);
  39. a[++cnt]=y1;
  40. a[++cnt]=y2;
  41. }
  42. sort(a+1,a+cnt+1);
  43. sort(e+1,e+ce+1,cmp);
  44. for(i=1;i<=ce;i++){
  45. if(e[i].t==0){
  46. ins(lower_bound(a+1,a+cnt+1,e[i].l)-a,e[i].v);
  47. }
  48. if(e[i].t==1){
  49. ans[e[i].v]+=sum(lower_bound(a+1,a+cnt+1,e[i].l)-a,lower_bound(a+1,a+cnt+1,e[i].r)-a);
  50. }
  51. if(e[i].t==2){
  52. ans[e[i].v]-=sum(lower_bound(a+1,a+cnt+1,e[i].l)-a,lower_bound(a+1,a+cnt+1,e[i].r)-a);
  53. }
  54. }
  55. for(i=1;i<=m;i++)puts(ans[i]==goal?"YES":"NO");
  56. }
  57. /*
  58. 2 3
  59. 0 0
  60. 0 1
  61. 1 0
  62. 1 2
  63. 2 0
  64. 2 -1
  65. 2 -2
  66. 2 -3
  67. 0 -1 2 0
  68. 0 -1 2 1
  69. 0 0 0 1
  70.  
  71. 1 1
  72. 0 0
  73. 0 1
  74. 1 0
  75. 1 2
  76. 0 -1 2 0
  77. */

  

G. Mosaic Tracery

找到度数为$2$的点作为角落然后开始构造。

H. List of Powers

若$r-l$比较小,那么可以枚举其中每个数,用BSGS检查。

否则$r-l$比较大,因为$a^k\bmod p$分布非常随机,而答案不超过$100$个,故周期很短,暴力枚举循环节内所有$k$即可。

注意BSGS检查次数比较多,可以通过增加步长,牺牲预处理复杂度来减少每次查询的复杂度。

  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. #include<tr1/unordered_set>
  15. using namespace std;
  16. using namespace std::tr1;
  17. void fre() { }
  18. #define MS(x, y) memset(x, y, sizeof(x))
  19. #define ls o<<1
  20. #define rs o<<1|1
  21. typedef long long LL;
  22. typedef unsigned long long UL;
  23. typedef unsigned int UI;
  24. template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b > a)a = b; }
  25. template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b < a)a = b; }
  26. const int N = 1e5 + 10, M = 0, Z = 1e9 + 7, inf = 0x3f3f3f3f;
  27. template <class T1, class T2>inline void gadd(T1 &a, T2 b) { a = (a + b) % Z; }
  28. int casenum, casei;
  29.  
  30. LL pow_mod(LL x, int y, int Z)
  31. {
  32. LL ans = 1;
  33. while(y){
  34. if(y & 1) ans = ans * x % Z;
  35. y >>= 1;
  36. x = x * x % Z;
  37. }
  38. return ans;
  39. }
  40.  
  41. int s;
  42. unordered_set<int> rec;
  43. int cur[N], powmod[N];
  44. void init(int m, int x)
  45. {
  46. s = (int) (sqrt((double)m));
  47. for(; (LL) s * s <= m;) s ++;
  48. int Cur = 1;
  49. for(int i = 0; i < s; i ++){
  50. rec.insert(Cur);
  51. Cur = 1LL * Cur * x % m;
  52. }
  53. int mul = Cur;
  54. cur[0] = 1; powmod[0] = pow_mod(cur[0], m - 2, m);
  55. for(int i = 1; i < s; i ++){
  56. cur[i] = 1LL * cur[i - 1] * mul % m;
  57. powmod[i] = pow_mod(cur[i], m - 2, m);
  58. }
  59.  
  60. }
  61.  
  62. LL discrete_log(int x, int n, int m)
  63. {
  64. for(int i = 0; i < s; i ++){
  65. int more = 1LL * n * powmod[i] % m;
  66. if(rec.find(more)!=rec.end()){
  67. return 1;
  68. }
  69. }
  70. return -1;
  71. }
  72.  
  73. int P, A, L, R;
  74. set<int>sot;
  75. set<int> :: iterator it;
  76.  
  77. inline LL po(LL a,LL b,LL p){
  78. b=(b%(p-1)+p-1)%(p-1);
  79. a%=p;
  80. LL t=1;
  81. for(;b;b>>=1LL,a=a*a%p)if(b&1)t=t*a%p;
  82. return t;
  83. }
  84.  
  85. int main()
  86. {
  87. scanf("%d%d%d%d", &P, &A, &L, &R);
  88. int phi=P-1;
  89. int per=phi;
  90. for(int i=1;i*i<=phi;i++)if(phi%i==0){
  91. if(po(A,i,P)==1)per=min(per,(int)(i));
  92. if(po(A,phi/i,P)==1)per=min(per,(int)(phi/i));
  93. }
  94. sot.clear();
  95. int lim = 1e8;
  96. if(R-L>2000){
  97. LL t = 1;
  98. for(int i = 1; i <= per; i ++){
  99. t = t * A;
  100. if(t==1)break;
  101. if(t >= P) t %= P;
  102. if(t <= R && t >= L){
  103. sot.insert(t);
  104. }
  105. //if(sot.size() >= 100) break;
  106. }
  107.  
  108. for(it = sot.begin(); it != sot.end(); it ++){
  109. printf("%d ", *it);
  110. }puts("");
  111. }
  112. else{
  113. vector<int> sot;
  114. init(P, A);
  115. for(int i = L; i <= R; i ++){
  116. if(discrete_log(A, i, P) != -1) sot.push_back(i);
  117. //if(sot.size() >= 100) break;
  118. }
  119.  
  120. for(auto it = sot.begin(); it != sot.end(); it ++){
  121. printf("%d ", *it);
  122. }puts("");
  123. }
  124. return 0;
  125. }
  126.  
  127. /*
  128. 【trick&&吐槽】
  129.  
  130. 【题意】
  131.  
  132. 【分析】
  133.  
  134. 【时间复杂度&&优化】
  135.  
  136. */

  

I. Potential Well

答案就是边权平均数最小的环,求出答案后就是差分约束系统模型,Bellman-Ford即可。

对于边权平均数最小的环,设$f[i][j]$表示经过$i$条边到达$j$的最短路,则:

\[ans=\min_{i=1}^n\{\max_{j=0}^{n-1}\frac{f[n][i]-f[j][i]}{n-j}\}\]

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

  1. #include<cstdio>
  2. typedef long long ll;
  3. const int N=1005,M=100005;
  4. const double inf=1e18;
  5. int n,m,i,j,u[M],v[M];double w[M],f[N][N],d[N],ans=inf,now,tmp;
  6. inline void up(double&a,double b){a>b?(a=b):0;}
  7. int main(){
  8. scanf("%d%d",&n,&m);
  9. for(i=1;i<=m;i++)scanf("%d%d%lf",&u[i],&v[i],&w[i]);
  10. for(i=1;i<=n;i++)for(j=1;j<=n;j++)f[i][j]=inf;
  11. for(i=0;i<n;i++)for(j=1;j<=m;j++)up(f[i+1][v[j]],f[i][u[j]]+w[j]);
  12. for(i=1;i<=n;i++)if(f[n][i]<inf/2){
  13. now=-inf;
  14. for(j=0;j<n;j++)if(f[j][i]<inf/2){
  15. tmp=1.0*(f[n][i]-f[j][i])/(n-j);
  16. if(now<tmp)now=tmp;
  17. }
  18. up(ans,now);
  19. }
  20. if(ans>inf/2)return puts("+inf"),0;
  21. for(i=1;i<=n;i++)for(j=1;j<=m;j++)up(d[v[j]],d[u[j]]+w[j]-ans);
  22. printf("%.10f\n",ans);
  23. for(i=1;i<=n;i++)printf("%.10f ",d[i]);
  24. }

  

J. Steiner Tree in Random Graph

留坑。

K. Rotation Transformation

列方程推公式即可,取精度误差最小的作为解。

  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() { }
  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. double a[4][4], b[4][4];
  28. const double PI = acos(-1.0), eps = 1e-8;
  29. int sgn(double x)
  30. {
  31. if(fabs(x) < eps) return 0;
  32. return x > 0 ? 1 : -1;
  33. }
  34. double th, sinth, costh, ux, uy, uz;
  35. int main()
  36. {
  37.  
  38. /*
  39. scanf("%lf", &th);
  40. th = th / 180 * PI;
  41. scanf("%lf%lf%lf", &ux, &uy, &uz);
  42. sinth = sin(th);
  43. costh = cos(th);
  44. b[1][1] = costh + ux * ux * (1 - costh);
  45. b[1][2] = ux * uy * (1 - costh) - uz * sinth;
  46. b[1][3] = ux * uz * (1 - costh) + uy * sinth;
  47. b[2][1] = uy * ux * (1 - costh) + uz * sinth;
  48. b[2][2] = costh + uy * uy * (1 - costh);
  49. b[2][3] = uy * uz * (1 - costh) - ux * sinth;
  50. b[3][1] = uz * ux * (1 - costh) - uy * sinth;
  51. b[3][2] = uz * uy * (1 - costh) + ux * sinth;
  52. b[3][3] = costh + uz * uz * (1 - costh);
  53. for(int i = 1; i <= 3; i ++){
  54. for(int j = 1; j <= 3; j ++){
  55. //if(sgn(a[i][j] - b[i][j])){
  56. //printf("%d %d %lf %lf", i, j, a[i][j], b[i][j]);
  57. //}
  58.  
  59. }
  60. }
  61. */
  62.  
  63. for(int i = 1; i <= 3; i ++){
  64. for(int j = 1; j <= 3; j ++){
  65. scanf("%lf", &a[i][j]);
  66. //a[i][j] = b[i][j];
  67. }
  68. }
  69.  
  70. uz = (a[2][1] - a[1][2]) / 2;
  71. uy = (a[1][3] - a[3][1]) / 2;
  72. ux = (a[3][2] - a[2][3]) / 2;
  73. sinth = uz * uz + uy * uy + ux * ux;
  74. sinth = sqrt(sinth);
  75. th = asin(sinth);
  76. if(sgn(sinth)){
  77. uz /= sinth;
  78. uy /= sinth;
  79. ux /= sinth;
  80. }
  81. else{
  82. ux = 0;
  83. uy = 0;
  84. uz = 1;
  85. }
  86.  
  87. double t[5];
  88. t[1] = th; t[2] = -th; t[3] = PI - th; t[4] = th - PI;
  89.  
  90. double differ = 1e9; int oo = 1;
  91. for(int o = 1; o <= 4; o ++){
  92. double tmp = 0;
  93.  
  94. sinth = sin(t[o]);
  95. costh = cos(t[o]);
  96. b[1][1] = costh + ux * ux * (1 - costh);
  97. b[1][2] = ux * uy * (1 - costh) - uz * sinth;
  98. b[1][3] = ux * uz * (1 - costh) + uy * sinth;
  99. b[2][1] = uy * ux * (1 - costh) + uz * sinth;
  100. b[2][2] = costh + uy * uy * (1 - costh);
  101. b[2][3] = uy * uz * (1 - costh) - ux * sinth;
  102. b[3][1] = uz * ux * (1 - costh) - uy * sinth;
  103. b[3][2] = uz * uy * (1 - costh) + ux * sinth;
  104. b[3][3] = costh + uz * uz * (1 - costh);
  105. for(int i = 1; i <= 3; i ++){
  106. for(int j = 1; j <= 3; j ++){
  107. tmp += fabs(a[i][j] - b[i][j]);
  108. }
  109. }
  110. //printf("tmp %d %.10f\n", o, tmp);
  111. if(sgn(tmp - differ) < 0){
  112. differ = tmp;
  113. oo = o;
  114. }
  115. }
  116. th = t[oo];
  117. //printf("differ = %.10f\n", differ);
  118. th = th / PI * 180;
  119.  
  120. printf("%.10f\n", th);
  121. printf("%.10f %.10f %.10f\n", ux, uy, uz);
  122. return 0;
  123. }
  124.  
  125. /*
  126. 【trick&&吐槽】
  127.  
  128. 【题意】
  129.  
  130. 【分析】
  131.  
  132. 【时间复杂度&&优化】
  133.  
  134. */

  

XV Open Cup named after E.V. Pankratiev. GP of Three Capitals的更多相关文章

  1. XV Open Cup named after E.V. Pankratiev. GP of Tatarstan

    A. Survival Route 留坑. B. Dispersed parentheses $f[i][j][k]$表示长度为$i$,未匹配的左括号数为$j$,最多的未匹配左括号数为$k$的方案数. ...

  2. XV Open Cup named after E.V. Pankratiev. GP of America

    A. Area of Effect 首先最优解中必有一个点在圆的边界上. 若半径就是$R$,则枚举一个点,然后把剩下的事件极角扫描即可,时间复杂度$O(m(n+m)\log(n+m))$. 否则圆必然 ...

  3. XV Open Cup named after E.V. Pankratiev. GP of Central Europe (AMPPZ-2014)--J.Cave

    给你一棵树,现在有m个专家,每个专家计划从$a_i$走到$b_i$, 经过的距离不超过$d_i$,现在让你找一个点,使得所有专家的路途都能经过这个点 令$S_i$表示满足第i个专家的所有点,先检查1可 ...

  4. XV Open Cup named after E.V. Pankratiev. GP of Central Europe (AMPPZ-2014)--B.Petrol

    多源最短路+并查集 #include <bits/stdc++.h> using namespace std; #define rep(i, j, k) for (int i = int( ...

  5. XV Open Cup named after E.V. Pankratiev. GP of Siberia-Swimming

    给出两个点,找到过这两个点的等角螺线,并求出中间的螺线长 $c = \frac{b}{a}$ $p = a \times c^{\frac{\theta}{angle}}$ 对弧线积分 #includ ...

  6. XVII Open Cup named after E.V. Pankratiev. GP of Two Capitals

    A. Artifact Guarding 选出的守卫需要满足$\max(a+b)\leq \sum a$,从小到大枚举每个值作为$\max(a+b)$,在权值线段树上找到最大的若干个$a$即可. 时间 ...

  7. XV Open Cup named after E.V. Pankratiev Stage 6, Grand Prix of Japan Problem J. Hyperrectangle

    题目大意: 给出一个$d$维矩形,第i维的范围是$[0, l_i]$. 求满足$x_1 + x_2 + ...x_d \leq s$ 的点构成的单纯形体积. $d, l_i \leq 300$ 题解: ...

  8. XVI Open Cup named after E.V. Pankratiev. GP of Eurasia

    A. Nanoassembly 首先用叉积判断是否在指定向量右侧,然后解出法线与给定直线的交点,再关于交点对称即可. #include<bits/stdc++.h> using names ...

  9. XVI Open Cup named after E.V. Pankratiev. GP of SPB

    A. Bubbles 枚举两个点,求出垂直平分线与$x$轴的交点,答案=交点数+1. 时间复杂度$O(n^2\log n)$. #include<cstdio> #include<a ...

随机推荐

  1. 微信小程序无法定位

    获取定位的时候报:errMsg:getLocation:fail:require permission desc 错 解决办法: 在app.js加入代码 //app.js新增如下代码 config = ...

  2. Web请求相关

    HTTP简介 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览器的传送 ...

  3. VisualSVN服务器的本地搭建和使用

    Subversion是优秀的版本控制工具,其具体的的优点和详细介绍,这里就不再多说. 首先来下载和搭建SVN服务器. 现在Subversion已经迁移到apache网站上了,下载地址: http:// ...

  4. phpstorm快捷键大全

    前言:这段时间换了编辑器,所以挺多命令也改变了 转载来自:https://www.jianshu.com/p/ffb24d61000d?utm_campaign=maleskine&utm_c ...

  5. About the Importance of Aim in Life

    Have an aim in life, or your energies will all be wasted.   ---R. Peters 人生应该树立目标,否则你的精力会白白浪费. ---彼得 ...

  6. How far away ? HDU - 2586 【LCA】【RMQ】【java】

    题目大意:求树上任意两点距离. 思路: dis[i]表示i到根的距离(手动选根),则u.v的距离=dis[u]+dis[v]-2*dis[lca(u,v)]. lca:u~v的dfs序列区间里,深度最 ...

  7. docker学习------docker私有仓库的搭建

    192.168.138.102:23451.私有仓库的搭建(docker pull registry),拉取最新的镜像 2.查看拉取的仓库镜像(docker images) 3.启用registry镜 ...

  8. JAVA写JSON的三种方法,java对象转json数据

    JAVA写JSON的三种方法,java对象转json数据 转自:http://www.xdx97.com/#/single?bid=5afe2ff9-8cd1-67cf-e7bc-437b74c07a ...

  9. 字符串常量池和String.intern()方法在jdk1.6、1.7、1.8中的变化

    字符串常量池也是运行时常量池 jdk1.6中,它是在方法区中,属于“永久代” jdk1.7中,它被移除方法区,放在java堆中 jdk1.8中,取消了“永久代”,将常量池放在元空间,与堆独立了 pub ...

  10. MATLAB更换编辑器配色方案

    MATLAB的默认编辑配色方案白色,长时间面对高亮度的白色界面容易产生眼睛疲劳的感觉,那么如何更换编辑器配色方案呢?经过不断探索以及查阅资料,发现了下列几种配色方案.配色文件来源于https://gi ...