topcoder srm 300 div1
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的更多相关文章
- 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 440 div1
problem1 link 二分答案,然后计算总时间.跟$T$比较确定要增大答案还是减小答案. problem2 link 可以看作是以‘*’所在位置为根的树.所以每个非根节点都有一个父节点. 那么每 ...
- topcoder srm 686 div1
problem1 link 左括号和右括号较少的一种不会大于20.假设左括号少.设$f[i][mask][k]$表示处理了前$i$个字符,其中留下的字符以$k$开头($k=0$表示'(',$k=1$表 ...
- 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& ...
随机推荐
- css抖动动画
button{ animation: beat 6s ease 0s infinite normal; } @keyframes beat { 0% { transform: translateY(0 ...
- rsa 加密 pkcs#1格式秘钥的格式化
C++调用openssl库生成的秘钥对,通过传输传出来的只有秘钥的内容,没有秘钥的格式.而我们在调用openssl库加密解密时,传入的秘钥是需要包含格式的.C++调用openssl库需要的格式为pkc ...
- GetLastError()返回值列表
GetLastError()返回值列表: [0]-操作成功完成.[1]-功能错误.[2]-系统找不到指定的文件.[3]-系统找不到指定的路径.[4]-系统无法打开文件.[5]-拒绝访问.[6]-句柄无 ...
- TP增删改
增加数据 <?php namespace Home\Controller; use Think\Controller; class IndexController extends Control ...
- centos安装java的jdk
1.下载 jdk-8u101-linux-x64.rpm http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads- ...
- sitecore系统教程之禁用xDB和Xdb跟踪
Sitecore体验管理包含未启用体验数据库(xDB)且无需购买xDB许可证情况下使用Sitecore内容管理系统. 除了在未启用xDB的情况下运行Sitecore Experience Platfo ...
- mvc未登录跳转到登录界面
编写一个mvc控制器基类BaseController , 其继承自controller 重写其OnActionExecuting方法, 在其中检测session值,如果没有,则跳转至登录页面. 如下
- C# foreach 中获取索引index的方法[转]
在C# 开发中往往使用foreach 循环语句 来代替for循环语句.foreach 比 for 更加简洁高效. foreach : foreach ...
- Linux基础命令---调整程序优先级renice
renice renice指令可以重新调整程序运行的优先级,可以通过进程id.用户id.组id来修改优先级.修改组的等级,影响组内所有用户的所有进程优先级:修改用户等级,影响该用户的所有进程优先级.除 ...
- python GIL 全局锁,多核cpu下的多线程性能究竟如何?
python GIL 全局锁,多核cpu下的多线程性能究竟如何?GIL全称Global Interpreter Lock GIL是什么? 首先需要明确的一点是GIL并不是Python的特性,它是在实现 ...