topcoder srm 445 div1
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的更多相关文章
- Topcoder SRM 643 Div1 250<peter_pan>
Topcoder SRM 643 Div1 250 Problem 给一个整数N,再给一个vector<long long>v; N可以表示成若干个素数的乘积,N=p0*p1*p2*... ...
- Topcoder Srm 726 Div1 Hard
Topcoder Srm 726 Div1 Hard 解题思路: 问题可以看做一个二分图,左边一个点向右边一段区间连边,匹配了左边一个点就能获得对应的权值,最大化所得到的权值的和. 然后可以证明一个结 ...
- topcoder srm 714 div1
problem1 link 倒着想.每次添加一个右括号再添加一个左括号,直到还原.那么每次的右括号的选择范围为当前左括号后面的右括号减去后面已经使用的右括号. problem2 link 令$h(x) ...
- topcoder srm 738 div1 FindThePerfectTriangle(枚举)
Problem Statement You are given the ints perimeter and area. Your task is to find a triangle wi ...
- Topcoder SRM 602 div1题解
打卡- Easy(250pts): 题目大意:rating2200及以上和2200以下的颜色是不一样的(我就是属于那个颜色比较菜的),有个人初始rating为X,然后每一场比赛他的rating如果增加 ...
- Topcoder SRM 627 div1 HappyLettersDiv1 : 字符串
Problem Statement The Happy Letter game is played as follows: At the beginning, several players ...
- Topcoder SRM 584 DIV1 600
思路太繁琐了 ,实在不想解释了 代码: #include<iostream> #include<cstdio> #include<string> #include& ...
- TopCoder SRM 605 DIV1
604的题解还没有写出来呢.先上605的. 代码去practice房间找. 说思路. A: 贪心,对于每个类型的正值求和,如果没有正值就取最大值,按着求出的值排序,枚举选多少个类型. B: 很明显是d ...
- 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)其 ...
随机推荐
- C# 语言 - 一个优雅的分页实现
这篇文章介绍分页对象的封装,如何优雅的对数据进行分页. 先上调用代码: 我们希望能在一个Enumerable对象后面直接.ToPagedList(pageIndex,pageSize)这样优雅的调用分 ...
- c# mongo 数组里对象更新
var queryDetail = new BsonDocument("cNo", doc.cNo); queryDetail.AddRan ...
- Python记录2:数据类型
一Python的数据类型可以分为可变与不可变两种: 可变类型:值改变,但是id不变,证明就是在改变原值,就是可变类型 如list dict 列表和字典都是可变类型 不可变类型:值改变,id也跟着改 ...
- [IDE] ECLIPSE取消自动更新
eclipse自动更新的取消方法: window --> preferences --> General --> Startup and Shutdown --> 在列表中找到 ...
- css 扩大点击范围
业务场景:比如某个按钮大小已经固定了,但是需求点击按钮周边就可以触发点击事件. 设置一下before属性里面的height,width就是设置你要点击的范围. rem是css3中新增加的一个单位属性( ...
- linux常用命令:cp 命令
cp命令用来复制文件或者目录,是Linux系统中最常用的命令之一.一般情况下,shell会设置一个别名,在命令行下复制文件时,如果目标文件已经存在,就会询问是否覆盖,不管你是否使用-i参数.但是如果是 ...
- USB接口案例——多态和转型
其中,为传递和使用的匿名对象,即创建了对象,但是没有引用类和对象名来接收: 电脑类中的操作usb的成员方法中,要向下转型,毛主席讲的具体问题具体分析,不同的设备有不同的操作:
- 复习loadRunner参数化
参数化: 为什么要用参数化? 如果是单一数据,那么会纯测试缓存. 如果是参数化,基本上大部分数据不会被缓存命中. 极端情况:所有的数据都不会被缓存命中,或者少量命中. 在loadrunner中,所有的 ...
- 实现私有化(Pimpl) --- QT常见的设计模式
转载自:http://blog.sina.com.cn/s/blog_667102dd0100wxbi.html 一.遇到的问题 1.隐藏实现 我们在给客户端提供接口的时候只希望能暴露它的接口,而隐藏 ...
- 用Javascript,DHTML控制表格的某一列的显示与隐藏
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or ...