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. undefined reference 问题各种情况分析

    扒自网友文章 关于undefined reference这样的问题,大家其实经常会遇到,在此,我以详细地示例给出常见错误的各种原因以及解决方法,希望对初学者有所帮助. 1.  链接时缺失了相关目标文件 ...

  2. 寻路——AI

    小球找到目标位置, 必要时候进行跳跃 进行跳跃时,需要在cube上加上  Off Mesh Link  组件,并添加起跳位置和目标位置 在static位置选Navigation static 编写脚本 ...

  3. db2字符串相关函数的使用

    db2字符串相关函数的使用 from :internet    一.字符转换函数 1.ASCII() 返回字符表达式最左端字符的ASCII 码值.在ASCII()函数中,纯数字的字符串可不用‘’括起来 ...

  4. Unity shader学习之半兰伯特光照模型

    半兰伯特光照模型,为Valve公司在开发游戏<半条命>时提出的一种技术,用于解决漫反射光无法到达区域无任凭明暗变化,丢失模型细节表现的问题. 其公式如下: Cdiffuse = Cligh ...

  5. 【转】基于Python的接口测试框架实例

    下面小编就为大家带来一篇基于Python的接口测试框架实例.小编觉得挺不错的,现在就分享给大家,也给大家做个参考.一起跟随小编过来看看吧   背景 最近公司在做消息推送,那么自然就会产生很多接口,测试 ...

  6. Lucene 个人领悟 (三)

    其实接下来就是贴一下代码,熟悉一下Lucene的正常工作流程,或者说怎么使用这个API,更深层次的东西这篇文章不会讲到. 上一篇文章也说了maven的配置,只要你电脑联网就可以下载下来.我贴一下代码. ...

  7. GUI常用对象介绍2

    %示意line对象的用法 hf=figure; hl=plot([:]); %示意line对象的属性 get(hl) %设置line的颜色 set(hl,'Color','r'); %设置每个点形状 ...

  8. How to install john deere service advisor 4.2.005 on win 10 64bit

    How to install john deere service advisor 4.2.005 with the February 2016 data base disks on a machin ...

  9. vue 加载更多2

    <template lang="html"> <div class="yo-scroll" :class="{'down':(sta ...

  10. mongoDB 的介绍

    一.常用的网站 MongoDB  --  2009年被发布 MongoDB的官网:  www.mongodb.org 可以下载安装包    和  使用文档 MongoDB国内官方网站:  www.mo ...