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& ...
随机推荐
- Nginx查看并发链接数
一.通过界面查看通过web界面查看时Nginx需要开启status模块,也就是安装Nginx时加上 --with-http_stub_status_module 一.通过界面查看 通过web界面查看时 ...
- 本地计算机上的SQLServer(MSSQLSERVER)服务启动后停止,某些服务在未由其他服务或程序使用时将自动停止
SQLServer的服务启动问题: 本地计算机上的SQLServer(MSSQLSERVER)服务启动后停止,某些服务在未由其他服务或程序使用时将自动停止 出现这个问题导致无法启动SQLServer服 ...
- sqlserver字符集问题(中文出乱码,排序错误等)
在创建sqlserver 数据库时未指定排序字符集,databases则会使用instances的排序规则.为了支持中文,需要设置成Chinese_PRC_CI_AS. (1)通过sql脚本修改 -- ...
- oauth2.0学习笔记(摘抄简化)
大量摘抄白话简明教程. 附:可以参考<RFC6749协议中文版及oauth2.0>文档 一.OAuth 白话简明教程 1.简述 http://www.cnblogs.com/Ceri/p/ ...
- OpenCV resources
http://blog.csdn.net/small_foxrabbit/article/details/39858149http://blog.csdn.net/wuyoy520/article/d ...
- 如何在Sitecore CMS中创建项目
从功能区 打开Sitecore的内容编辑器,选择内容树中的项目.创建的项目将作为所选项目的子项添加. Sitecore 8显示所选的Home项目 Sitecore 6和7显示所选的Home项目 功能区 ...
- python中常见的错误类型
Python异常类 Python是面向对象语言,所以程序抛出的异常也是类.常见的Python异常有以下几个 ,大家只要大致扫一眼,有个映像,等到编程的时候,相信大家肯定会不只一次跟他们照面(除非你不用 ...
- flask 在模板中渲染表单
在模板中渲染表单 为了能够在模板中渲染表单,我们需要把表单类实例传入模板.首先在视图函数里实例化表单类LoginForm,然后再render_template()函数中使用关键脑子参数form将表单实 ...
- formdata 和 Payload 区别
FormData和Payload是浏览器传输给接口的两种格式,这两种方式浏览器是通过Content-Type来进行区分的(了解Content-Type),如果是 application/x-www-f ...
- 干货 | JavaScript内存空间详解
JS栈内存与堆内存 var a = 20; var b = 'abc'; var c = true; var d = { m: 20 } 因为JavaScript具有自动垃圾回收机制,所以对于前端开发 ...