problem1 link

这个的结论是只需要考虑坐标是整数或者是整数.5,比如(2.5,3),(4,3.5),(1.5,4.5)这样的时候。这个详细证明起来应该挺麻烦的。这里有一些讨论。

problem2 link

首先,可以暴力看下$n=3,4$时的情况。

$n=3$,

000

001

011

010

110

100

101

111

$n=4$,

0000

0001

0011

0010

0110

0100

0101

0111

1111

1000

1001

1011

1010

1110

1100

1101

这时候可以发现,规律是最高位从0变到1的时候,后面的位数进行了一次shift。

而题目是求最大值,即getMax(n,k)。

(1)当$k\leq 2^{n-1}$时,getMax(n,k)="0"+getMax(n-1,k)

(2)当$k=1+ 2^{n-1}$时,getMax(n,k)="1"+get(n-1,$2^{n-1}$)

(3)当$k>1+ 2^{n-1}$时,getMax(n,k)="1"+max(get(n-1,$2^{n-1}$),getMax(n-1,k-m-1))

其中,get(n,k)表示得到长度为$n$的第$k$个串。

problem3 link

可以把问题转化为可以构造多少种不同的长度为52的(msg,encMsg)二元对(只是msg中是已经排序的)。现在$msg$中的某些位置已经确定。只需要考虑那些未确定的即可。

每次可以选择一个在原串中未确定的最小(防止重复)的,枚举它匹配加密串中未确定的每一个可合法匹配的。

另外,在原串中,一个字符可能使用了0次、1次、2次,也就是还可以使用2次、1次、0次,同样一个字符在加密串中还可以使用2次、1次、0次。所以搭配一下有3*3=9种情况,(x,y)表示在原串中还可以使用$x$次,在加密串中还可以使用$y$次的的字符种类数

那么每次需要从(2,*),(1,*)中选择一个匹配(*,1)或者(*,2)中的一个。

code for problem1

  1. import java.util.*;
  2. import java.math.*;
  3. import static java.lang.Math.*;
  4.  
  5. public class TheNewHouseDivOne {
  6.  
  7. public double distance(int[] x, int[] y, int k) {
  8. double min=1e10;
  9. double[] a=new double[x.length];
  10. for(int i=0;i<=200;++i) {
  11. for(int j=0;j<=200;++j) {
  12. final double xx=-50+i*0.5;
  13. final double yy=-50+j*0.5;
  14. for(int t=0;t<x.length;++t) {
  15. a[t]=Math.abs(xx-x[t])+Math.abs(yy-y[t]);
  16. }
  17. Arrays.sort(a);
  18. if(a[k-1]<min) {
  19. min=a[k-1];
  20. }
  21. }
  22. }
  23. return min;
  24. }
  25. }

  

code for problem2

  1. import java.util.*;
  2. import java.math.*;
  3. import static java.lang.Math.*;
  4.  
  5. public class TheLockDivOne {
  6.  
  7. public String password(int n, long k) {
  8. return getMax(n,k);
  9. }
  10.  
  11. String getMax(int n,long k) {
  12. if(n==1) {
  13. return k==1?"0":"1";
  14. }
  15. long m=1l<<(n-1);
  16. if(k<=m) {
  17. return "0"+getMax(n-1,k);
  18. }
  19. else if(k==m+1) {
  20. return "1"+get(n-1,m);
  21. }
  22. else {
  23. String a=get(n-1,m);
  24. String b=getMax(n-1,k-m-1);
  25. if(a.compareTo(b)<0) {
  26. return "1"+b;
  27. }
  28. return "1"+a;
  29. }
  30. }
  31.  
  32. String get(int n,long k) {
  33. if(n==1) {
  34. return k==1?"0":"1";
  35. }
  36. long m=1l<<(n-1);
  37. if(k<=m) {
  38. return "0"+get(n-1,k);
  39. }
  40. else if(k==m+1) {
  41. return "1"+get(n-1,m);
  42. }
  43. else {
  44. return "1"+get(n-1,k-m-1);
  45. }
  46. }
  47. }

 

code for problem3

  1. import java.util.*;
  2. import java.math.*;
  3. import static java.lang.Math.*;
  4.  
  5. public class TheEncryptionDivOne {
  6.  
  7. static final int MOD=1234567891;
  8.  
  9. Map<Long,Integer> map=new HashMap<>();
  10.  
  11. public int count(String msg, String encMsg) {
  12. int[] p=new int[52];
  13. int[] q=new int[52];
  14. Arrays.fill(p,-1);
  15. Arrays.fill(q,-1);
  16. for(int i=0;i<msg.length();++i) {
  17. int u=get(msg.charAt(i));
  18. int v=get(encMsg.charAt(i));
  19. if(u%26==v%26) {
  20. return 0;
  21. }
  22. if(p[u]!=-1&&p[u]!=v||q[v]!=-1&&q[v]!=u) {
  23. return 0;
  24. }
  25. p[u]=v;
  26. q[v]=u;
  27. }
  28. int[][] c=new int[3][3];
  29. for(int i=0;i<26;++i) {
  30. int x=0,y=0;
  31. if(p[i]==-1) {
  32. ++x;
  33. }
  34. if(p[i+26]==-1) {
  35. ++x;
  36. }
  37. if(q[i]==-1) {
  38. ++y;
  39. }
  40. if(q[i+26]==-1) {
  41. ++y;
  42. }
  43. ++c[x][y];
  44. }
  45. return dfs(c);
  46. }
  47.  
  48. int dfs(int[][] c){
  49. final long h=hash(c);
  50. if(map.containsKey(h)) {
  51. return map.get(h);
  52. }
  53. int c1=-1,c2=0;
  54. for(int i=2;i>=1&&c1==-1;--i) {
  55. for(int j=2;j>=0;--j) {
  56. if(c[i][j]>0) {
  57. c1=i;
  58. c2=j;
  59. break;
  60. }
  61. }
  62. }
  63.  
  64. if(c1==-1) {
  65. map.put(h,1);
  66. return 1;
  67. }
  68.  
  69. int result=0;
  70. for(int i=2;i>=0;--i) {
  71. for(int j=2;j>=1;--j) {
  72. if(c[i][j]==0) {
  73. continue;
  74. }
  75. long num=c[i][j]*j;
  76. if(i==c1&&j==c2) {
  77. num-=j;
  78. }
  79. if(num<=0) {
  80. continue;
  81. }
  82. --c[i][j];
  83. --c[c1][c2];
  84. ++c[i][j-1];
  85. ++c[c1-1][c2];
  86. result=(int)((result+dfs(c)*num)%MOD);
  87. ++c[i][j];
  88. ++c[c1][c2];
  89. --c[i][j-1];
  90. --c[c1-1][c2];
  91. }
  92. }
  93.  
  94. map.put(h,result);
  95. return result;
  96. }
  97.  
  98. int get(char c) {
  99. if(c>='A'&&c<='Z') {
  100. return c-'A';
  101. }
  102. return c-'a'+26;
  103. }
  104. long hash(int[][] c) {
  105. long ans=0;
  106. for(int i=0;i<3;++i) {
  107. for(int j=0;j<3;++j) {
  108. ans=(ans<<5)|c[i][j];
  109. }
  110. }
  111. return ans;
  112. }
  113. }

  

topcoder srm 445 div1的更多相关文章

  1. Topcoder SRM 643 Div1 250<peter_pan>

    Topcoder SRM 643 Div1 250 Problem 给一个整数N,再给一个vector<long long>v; N可以表示成若干个素数的乘积,N=p0*p1*p2*... ...

  2. Topcoder Srm 726 Div1 Hard

    Topcoder Srm 726 Div1 Hard 解题思路: 问题可以看做一个二分图,左边一个点向右边一段区间连边,匹配了左边一个点就能获得对应的权值,最大化所得到的权值的和. 然后可以证明一个结 ...

  3. topcoder srm 714 div1

    problem1 link 倒着想.每次添加一个右括号再添加一个左括号,直到还原.那么每次的右括号的选择范围为当前左括号后面的右括号减去后面已经使用的右括号. problem2 link 令$h(x) ...

  4. topcoder srm 738 div1 FindThePerfectTriangle(枚举)

    Problem Statement      You are given the ints perimeter and area. Your task is to find a triangle wi ...

  5. Topcoder SRM 602 div1题解

    打卡- Easy(250pts): 题目大意:rating2200及以上和2200以下的颜色是不一样的(我就是属于那个颜色比较菜的),有个人初始rating为X,然后每一场比赛他的rating如果增加 ...

  6. Topcoder SRM 627 div1 HappyLettersDiv1 : 字符串

    Problem Statement      The Happy Letter game is played as follows: At the beginning, several players ...

  7. Topcoder SRM 584 DIV1 600

    思路太繁琐了 ,实在不想解释了 代码: #include<iostream> #include<cstdio> #include<string> #include& ...

  8. TopCoder SRM 605 DIV1

    604的题解还没有写出来呢.先上605的. 代码去practice房间找. 说思路. A: 贪心,对于每个类型的正值求和,如果没有正值就取最大值,按着求出的值排序,枚举选多少个类型. B: 很明显是d ...

  9. topcoder srm 575 div1

    problem1 link 如果$k$是先手必胜那么$f(k)=1$否则$f(k)=0$ 通过对前面小的数字的计算可以发现:(1)$f(2k+1)=0$,(2)$f(2^{2k+1})=0$,(3)其 ...

随机推荐

  1. C# 语言 - 一个优雅的分页实现

    这篇文章介绍分页对象的封装,如何优雅的对数据进行分页. 先上调用代码: 我们希望能在一个Enumerable对象后面直接.ToPagedList(pageIndex,pageSize)这样优雅的调用分 ...

  2. c# mongo 数组里对象更新

    var queryDetail = new BsonDocument("cNo", doc.cNo);                     queryDetail.AddRan ...

  3. Python记录2:数据类型

    一Python的数据类型可以分为可变与不可变两种: 可变类型:值改变,但是id不变,证明就是在改变原值,就是可变类型 如list   dict 列表和字典都是可变类型 不可变类型:值改变,id也跟着改 ...

  4. [IDE] ECLIPSE取消自动更新

    eclipse自动更新的取消方法: window --> preferences --> General --> Startup and Shutdown --> 在列表中找到 ...

  5. css 扩大点击范围

    业务场景:比如某个按钮大小已经固定了,但是需求点击按钮周边就可以触发点击事件. 设置一下before属性里面的height,width就是设置你要点击的范围. rem是css3中新增加的一个单位属性( ...

  6. linux常用命令:cp 命令

    cp命令用来复制文件或者目录,是Linux系统中最常用的命令之一.一般情况下,shell会设置一个别名,在命令行下复制文件时,如果目标文件已经存在,就会询问是否覆盖,不管你是否使用-i参数.但是如果是 ...

  7. USB接口案例——多态和转型

    其中,为传递和使用的匿名对象,即创建了对象,但是没有引用类和对象名来接收: 电脑类中的操作usb的成员方法中,要向下转型,毛主席讲的具体问题具体分析,不同的设备有不同的操作:

  8. 复习loadRunner参数化

    参数化: 为什么要用参数化? 如果是单一数据,那么会纯测试缓存. 如果是参数化,基本上大部分数据不会被缓存命中. 极端情况:所有的数据都不会被缓存命中,或者少量命中. 在loadrunner中,所有的 ...

  9. 实现私有化(Pimpl) --- QT常见的设计模式

    转载自:http://blog.sina.com.cn/s/blog_667102dd0100wxbi.html 一.遇到的问题 1.隐藏实现 我们在给客户端提供接口的时候只希望能暴露它的接口,而隐藏 ...

  10. 用Javascript,DHTML控制表格的某一列的显示与隐藏

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or ...