problem1 link

直接模拟即可。

import java.util.*;
import java.math.*;
import static java.lang.Math.*; public class Dating { static boolean sametype(char c1,char c2) {
return 'a'<=c1&&c1<='z'&&'a'<=c2&&c2<='z'
||'A'<=c1&&c1<='Z'&&'A'<=c2&&c2<='Z';
} public String dates(String circle, int k) {
StringBuilder builder=new StringBuilder();
int startIndex=0;
while(true) {
boolean lower=false;
boolean upper=false;
for(int i=0;i<circle.length();++i) {
char c=circle.charAt(i);
if('a'<=c&&c<='z') {
lower=true;
}
else {
upper=true;
}
if(lower&&upper) {
break;
}
}
if(!lower||!upper) {
break;
}
for(int i=0;i<k-1;++i) {
++startIndex;
if(startIndex==circle.length()) {
startIndex=0;
}
}
int chooseIndex=-1;
for(int i=0;i<circle.length();++i) {
if(i==startIndex) {
continue;
}
char c1=circle.charAt(i);
char c2=circle.charAt(startIndex);
if(!sametype(c1,c2)) {
if(chooseIndex==-1||circle.charAt(chooseIndex)>c1) {
chooseIndex=i;
}
}
}
if(builder.length()>0) {
builder.append(" ");
}
builder.append(circle.charAt(startIndex)).append(circle.charAt(chooseIndex));
if(chooseIndex<startIndex) {
circle=circle.substring(0,chooseIndex)+
circle.substring(chooseIndex+1,startIndex)+
circle.substring(startIndex+1);
startIndex-=1;
if(startIndex==circle.length()) {
startIndex=0;
}
}
else {
circle=circle.substring(0,startIndex)+
circle.substring(startIndex+1,chooseIndex)+
circle.substring(chooseIndex+1);
if(startIndex==circle.length()) {
startIndex=0;
}
}
}
return builder.toString();
}
}

problem2 link

设$h(x)$表示$[1,x]$范围内有多少符合要求的数字,那么题意就是计算$h(high)-h(low-1)$。

对于$h(n)$来说,设$n$有$d$位数字,$f(x)(y)(z)$表示已经考虑的数字的高$x$位,$y$表示已经考虑的数字中跟$n$的高$x$位相等还是小于还是已经考虑的高$x$位都是0,三种情况;$y$表示前一位数字是多少。

import java.util.*;
import java.math.*;
import static java.lang.Math.*; public class JumpyNum { int[][][] f=null;
int[] digit=null; int dfs(int d,int tag,int pre) {
if(d<0) {
return tag==2?0:1;
}
if(f[d][tag][pre]!=-1) {
return f[d][tag][pre];
}
int result=0;
for(int i=0;i<10;++i) {
if(tag==0) {
if(Math.abs(i-pre)>=2) {
result+=dfs(d-1,0,i);
}
}
else if(tag==1) {
if(i<=digit[d]&&Math.abs(i-pre)>=2) {
result+=dfs(d-1,i==digit[d]?1:0,i);
}
}
else {
result+=dfs(d-1,i==0?2:0,i);
}
}
return f[d][tag][pre]=result;
} int cal(int n) {
if(n<10) {
return n;
}
int d=String.valueOf(n).length();
digit=new int[d];
for(int i=0;i<d;++i) {
digit[i]=n%10;
n/=10;
}
f=new int[d][3][10];
for(int i=0;i<d;++i) {
for(int j=0;j<3;++j) {
for(int k=0;k<10;++k) {
f[i][j][k]=-1;
}
}
}
int result=0;
for(int i=0;i<=digit[d-1];++i) {
if(i==0) {
result+=dfs(d-2,2,0);
}
else {
result+=dfs(d-2,i==digit[d-1]?1:0,i);
}
}
return result;
} public int howMany(int low, int high) {
return cal(high)-cal(low-1);
}
}

 

problem3 link

首先求出与$x$轴的所有交点,然后每两个相邻交点的中间的范围都有可能被绕过若干圈(如果它不在外部或者边上)。这时可以取中间值进行计算。

对于某个点,将其与每条边的两个端点连线,计算转过的角度即可。如果在外部,那么转过的总角度是0,在内部一定是$2\pi$的若干倍。

对于两个向量$\vec{a},\vec{b}$,可以用$arctan(t)$来计算转角,其中$t=\frac{cross(\vec{a},\vec{b})}{dot(\vec{a},\vec{b})}$。因为$\frac{dot(\vec{a},\vec{b})}{|\vec{a}|}$表示$\vec{b}$在$\vec{a}$上的投影长度,$\frac{cross(\vec{a},\vec{b})}{|\vec{a}|}$表示以$\vec{a},\vec{b}$为边的平行四边形的高(面积除以底边长),所以它们的比值就是转角的正切值。

import java.util.*;
import java.math.*;
import static java.lang.Math.*; class point
{
public double x;
public double y; public point(){}
public point(double x,double y) {
this.x=x;
this.y=y;
} public double crossMultiply(point a)
{
return x*a.y-y*a.x;
} public point substract(point a)
{
return new point(x-a.x,y-a.y);
} public double dotMultiply(point a)
{
return x*a.x+y*a.y;
} public double calculateAngle(point a)
{
return Math.atan2(crossMultiply(a),dotMultiply(a));
} public void print()
{
System.out.println("x="+x+", y="+y);
}
}; public class AllWoundUp { static int cal(double t,int[] px,int[] py) {
double sum=0;
final int n=px.length;
for(int i=0;i<n;++i) {
int x0=px[i],y0=py[i];
int x1=px[(i+1) % n],y1=py[(i+1)%n];
if(y0==y1&&y0==0) {
continue;
}
sum+=new point(x0-t,y0).calculateAngle(new point(x1-t,y1));
}
return (int)(sum/2/Math.PI+0.5); } public int maxWind(int[] x, int[] y) { List<Double> list=new ArrayList<>();
final int n=x.length;
for(int i=0;i<n;++i) {
int x0=x[i],y0=y[i];
int x1=x[(i+1)%n],y1=y[(i+1)%n];
if(y0==y1) {
continue;
}
if(x0==x1) {
if(y0*y1<=0) {
list.add((double)x0);
}
continue;
}
if(y0*y1>0) {
continue;
}
double k=1.0*(y0-y1)/(x0-x1);
list.add(-y0/k+x0);
}
Collections.sort(list);
int result=0;
for(int i=1;i<list.size();++i) {
if(Math.abs(list.get(i)-list.get(i-1))<1e-10) {
continue;
}
double t=(list.get(i)+list.get(i-1))/2;
boolean tag=false;
for(int j=0;j<n;++j) {
int x0=x[j],y0=y[j];
int x1=x[(j+1)%n],y1=y[(j+1)%n];
if(y0==y1&&y0==0&&Math.min(x0,x1)<=t&&t<=Math.max(x0,x1)) {
tag=true;
break;
}
}
if(tag) {
continue;
}
result=Math.max(result,cal(t,x,y));
}
return result;
}
}

  

topcoder srm 300 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 440 div1

    problem1 link 二分答案,然后计算总时间.跟$T$比较确定要增大答案还是减小答案. problem2 link 可以看作是以‘*’所在位置为根的树.所以每个非根节点都有一个父节点. 那么每 ...

  4. topcoder srm 686 div1

    problem1 link 左括号和右括号较少的一种不会大于20.假设左括号少.设$f[i][mask][k]$表示处理了前$i$个字符,其中留下的字符以$k$开头($k=0$表示'(',$k=1$表 ...

  5. topcoder srm 714 div1

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

  6. topcoder srm 738 div1 FindThePerfectTriangle(枚举)

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

  7. Topcoder SRM 602 div1题解

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

  8. Topcoder SRM 627 div1 HappyLettersDiv1 : 字符串

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

  9. Topcoder SRM 584 DIV1 600

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

随机推荐

  1. [4]传奇3服务器源码分析一 SelGate

    1. 2 留存 服务端下载地址: 点击这里

  2. shell作业控制(后台前台命令)

    ctrl+z暂停命令(任务) fg调回命令    |          fg +id号 bg放在后台持续执行 vmstat 1 &  在后面加上‘&’ 即相当于bg jobs列出当前的 ...

  3. sitecore系统教程之Item快速了解

    项目是Sitecore网站的基本构建块.项目可以表示构成网页的任何类型的信息,例如,一段文本,媒体文件,布局等. 项目始终具有名称,唯一标识项目的ID,并且它基于定义项目包含的字段的模板.此外,项目可 ...

  4. 【Linux学习八】脚本编程

    环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 一.多层bash#.和source都是当前bash [root@nod ...

  5. django之视图view小知识

    CBV简版流程 AddPublisher.as_view() ——> view 函数 当请求来的时候才执行view view中执行: 1. 先实例化AddPublisher,给self def ...

  6. 浅谈大数据与hadoop家族

    按照时间的早晚从大数据出现之前的时代讲到现在.暂时按一个城市来比喻吧,反正Landscape的意思也大概是”风景“的意思. 早在大数据概念出现以前就存在了各种各样的关于数学.统计学.算法.编程语言的研 ...

  7. linux监控性能和网络的命令

    vmstat查看机器实时的综合情况:load,内存,swap,cpu使用率等方面 procs: r:运行队列中进程数量 b:等待IO的进程数量 memory(内存): swpd:使用虚拟内存大小 fr ...

  8. 读QT5.7源码(三)Q_OBJECT 和QMetaObject

    Qt meta-object系统基于三个方面:  1.QObject提供一个基类,方便派生类使用meta-object系统的功能:  2.Q_OBJECT宏,在类的声明体内激活meta-object功 ...

  9. 洛谷 P1106 删数问题

    一定要认真审题   “去掉其中任意k个数字后剩下的数字按原左右次序将组成一个新的正整数”   也就是说 输入:7893400   4     输出:300  (00在原顺序中位于3后边) 输入:789 ...

  10. linux学习笔记---grep

    先来讲讲grep(搜索过滤) 1.命令格式: grep [option] pattern file 2.命令参数: -a 不要忽略二进制的数据 -A<显示行数>          除了显示 ...