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

import java.util.*;
import java.math.*;
import static java.lang.Math.*; public class TheNewHouseDivOne { public double distance(int[] x, int[] y, int k) {
double min=1e10;
double[] a=new double[x.length];
for(int i=0;i<=200;++i) {
for(int j=0;j<=200;++j) {
final double xx=-50+i*0.5;
final double yy=-50+j*0.5;
for(int t=0;t<x.length;++t) {
a[t]=Math.abs(xx-x[t])+Math.abs(yy-y[t]);
}
Arrays.sort(a);
if(a[k-1]<min) {
min=a[k-1];
}
}
}
return min;
}
}

  

code for problem2

import java.util.*;
import java.math.*;
import static java.lang.Math.*; public class TheLockDivOne { public String password(int n, long k) {
return getMax(n,k);
} String getMax(int n,long k) {
if(n==1) {
return k==1?"0":"1";
}
long m=1l<<(n-1);
if(k<=m) {
return "0"+getMax(n-1,k);
}
else if(k==m+1) {
return "1"+get(n-1,m);
}
else {
String a=get(n-1,m);
String b=getMax(n-1,k-m-1);
if(a.compareTo(b)<0) {
return "1"+b;
}
return "1"+a;
}
} String get(int n,long k) {
if(n==1) {
return k==1?"0":"1";
}
long m=1l<<(n-1);
if(k<=m) {
return "0"+get(n-1,k);
}
else if(k==m+1) {
return "1"+get(n-1,m);
}
else {
return "1"+get(n-1,k-m-1);
}
}
}

 

code for problem3

import java.util.*;
import java.math.*;
import static java.lang.Math.*; public class TheEncryptionDivOne { static final int MOD=1234567891; Map<Long,Integer> map=new HashMap<>(); public int count(String msg, String encMsg) {
int[] p=new int[52];
int[] q=new int[52];
Arrays.fill(p,-1);
Arrays.fill(q,-1);
for(int i=0;i<msg.length();++i) {
int u=get(msg.charAt(i));
int v=get(encMsg.charAt(i));
if(u%26==v%26) {
return 0;
}
if(p[u]!=-1&&p[u]!=v||q[v]!=-1&&q[v]!=u) {
return 0;
}
p[u]=v;
q[v]=u;
}
int[][] c=new int[3][3];
for(int i=0;i<26;++i) {
int x=0,y=0;
if(p[i]==-1) {
++x;
}
if(p[i+26]==-1) {
++x;
}
if(q[i]==-1) {
++y;
}
if(q[i+26]==-1) {
++y;
}
++c[x][y];
}
return dfs(c);
} int dfs(int[][] c){
final long h=hash(c);
if(map.containsKey(h)) {
return map.get(h);
}
int c1=-1,c2=0;
for(int i=2;i>=1&&c1==-1;--i) {
for(int j=2;j>=0;--j) {
if(c[i][j]>0) {
c1=i;
c2=j;
break;
}
}
} if(c1==-1) {
map.put(h,1);
return 1;
} int result=0;
for(int i=2;i>=0;--i) {
for(int j=2;j>=1;--j) {
if(c[i][j]==0) {
continue;
}
long num=c[i][j]*j;
if(i==c1&&j==c2) {
num-=j;
}
if(num<=0) {
continue;
}
--c[i][j];
--c[c1][c2];
++c[i][j-1];
++c[c1-1][c2];
result=(int)((result+dfs(c)*num)%MOD);
++c[i][j];
++c[c1][c2];
--c[i][j-1];
--c[c1-1][c2];
}
} map.put(h,result);
return result;
} int get(char c) {
if(c>='A'&&c<='Z') {
return c-'A';
}
return c-'a'+26;
}
long hash(int[][] c) {
long ans=0;
for(int i=0;i<3;++i) {
for(int j=0;j<3;++j) {
ans=(ans<<5)|c[i][j];
}
}
return ans;
}
}

  

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. react结合redux开发

    先加上我码云的地址:https://gitee.com/ldlx/react_and_rudex

  2. InstallShield2015创建安装包

    1.新建  InstallScript MSI Project工程 a)输入项目名称Project Name:  XBS(例如) b)输入创建目录Location:   C:\(例如) c)如果勾选“ ...

  3. MyBatis基础入门《四》接口方式.Select查询集合

    MyBatis基础入门<四>接口方式.Select查询集合 描述: 在<MyBatis基础入门<二>Select查询>中有说过,SQLSession有两种用法,这里 ...

  4. 原型链(_proto_) 与原型(prototype) 有啥关系?

    prototype对象里面方法及属性是共享的...... 1.JavaScript 中每一个对象都拥有原型链(__proto__)指向其构造函数的原型( prototype),object._prot ...

  5. c#如何判断字符串是否含中文

    如代码: static bool ContainChinese(string input) { string pattern = "[\u4e00-\u9fbb]"; return ...

  6. Vue系列之 => 通过vue-resource发起ajax请求

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. loadRunner回访脚本时报Error -27987: Requested image not found [MsgId: MERR-27987]

    loadRunner录制:登陆订机票网址->订机票的过程 loadRunner回访脚本时报Error -27987: Requested image not found  [MsgId: MER ...

  8. CATALINA_OPTS和 JAVA_OPTS区别

    在Tomcat的catalina.sh文件中的启停server脚本中都应用到了两个变量: CATALINA_OPTS和JAVA_OPTS.用于保存Tomcat运行所需的各种参数. 他们在文件中的注释如 ...

  9. JustOj 2040: 王胖子买零食 (贪心)

    题目描述 大豪哥有个好朋友叫王胖子,众所周知王胖子特别爱吃零食,比如各种不一样的糖果,辣条呀,可是王胖子每个月用在买零食上的钱不是固定的,但是因为王胖子特别爱吃零食,他希望把自己能花在买吃的钱全部用掉 ...

  10. bzoj4443 小凸玩矩阵

    题目链接 二分+最大check #include<algorithm> #include<iostream> #include<cstdlib> #include& ...