HDU 6351暴力枚举 6354计算几何
Beautiful Now
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1876 Accepted Submission(s): 707
Let the decimal representation of n as (x1x2⋯xm)10 satisfying that 1≤x1≤9, 0≤xi≤9 (2≤i≤m), which means n=∑mi=1xi10m−i. In each swap, Anton can select two digits xi and xj (1≤i≤j≤m) and then swap them if the integer after this swap has no leading zero.
Could you please tell him the minimum integer and the maximum integer he can obtain after k swaps?
Each of the following T lines describes a test case and contains two space-separated integers n and k.
1≤T≤100, 1≤n,k≤109.
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define fillchar(a, x) memset(a, x, sizeof(a))
#define huan printf("\n");
#define debug(a,b) cout<<a<<" "<<b<<" "<<endl;
using namespace std;
typedef long long ll;
const ll maxn=1e7+,inf=1e18;
const ll mod=1e9+;
vector<int> per[][];
int vis[],a[],b[];
void init()
{
for(int i=;i<=;i++)
{
for(int j=;j<=i;j++)
a[j]=j;
do
{
fillchar(vis,);
int now=,temp=;
for(int j=;j<=i;j++)
now=now*+a[j];
for(int j=;j<=i;j++)
{
if(vis[j]==)
{
vis[j]=;
for(int k=a[j];k!=j;k=a[k])
vis[k]=,temp++;
}
}
per[i][temp].pb(now);
}while(next_permutation(a+,a+i+));
}
}
char s[];
int main()
{
int n,m,t,k,maxx,minn;
init();
cin>>t;
while(t--)
{
cin>>n>>k;
minn=maxx=n;
int len=sprintf(s,"%d",n);
if(len==)
{
printf("%d %d\n",minn,maxx);
continue;
}
reverse(s,s+len);
if(len<=k)k=len-;
for(int i=;i<=k;i++)
{
for(int j=;j<per[len][i].size();j++)
{
int temp=per[len][i][j],cnt=,sum=;
while(temp)
{
sum=sum*+int(s[temp%-]-'');
temp/=;
}
//cout<<per[len][i][j]<<" "<<sum<<endl;
if((int)pow(,len-)>sum)continue;
maxx=max(maxx,sum);
minn=min(minn,sum);
}
}
printf("%d %d\n",minn,maxx);
}
}
http://acm.hdu.edu.cn/showproblem.php?pid=6354
解析 内切的直接把周长加起来 相交的减去原来的弧长 加上另一个圆的弧长 根据余弦定理可以算出来角度 角度*半径就是弧长了
#include <bits/stdc++.h>
#define LL long long
#define PI 3.1415926535897932384626
#define maxn 1000
#define EXIT exit(0);
#define DEBUG puts("Here is a BUG");
#define CLEAR(name, init) memset(name, init, sizeof(name))
const double eps = 1e-;
const int MAXN = (int)1e9 + ;
using namespace std;
#define Vector Point
int dcmp(double x)
{
return fabs(x) < eps ? : (x < ? - : );
}
struct Point
{
double x, y; Point(const Point& rhs): x(rhs.x), y(rhs.y) { } //拷贝构造函数
Point(double x = 0.0, double y = 0.0): x(x), y(y) { } //构造函数
friend istream& operator >> (istream& in, Point& P)
{
return in >> P.x >> P.y;
}
friend ostream& operator << (ostream& out, const Point& P)
{
return out << P.x << ' ' << P.y;
}
friend Vector operator + (const Vector& A, const Vector& B)
{
return Vector(A.x+B.x, A.y+B.y);
}
friend Vector operator - (const Point& A, const Point& B)
{
return Vector(A.x-B.x, A.y-B.y);
}
friend Vector operator * (const Vector& A, const double& p)
{
return Vector(A.x*p, A.y*p);
}
friend Vector operator / (const Vector& A, const double& p)
{
return Vector(A.x/p, A.y/p);
}
friend bool operator == (const Point& A, const Point& B)
{
return dcmp(A.x-B.x) == && dcmp(A.y-B.y) == ;
}
friend bool operator < (const Point& A, const Point& B)
{
return A.x < B.x || (A.x == B.x && A.y < B.y);
}
void in(void)
{
scanf("%lf%lf", &x, &y);
}
void out(void)
{
printf("%lf %lf", x, y);
}
};
template <class T> T sqr(T x)
{
return x * x;
}
double Dot(const Vector& A, const Vector& B)
{
return A.x*B.x + A.y*B.y; //点积
}
double Length(const Vector& A)
{
return sqrt(Dot(A, A));
}
double Angle(const Vector& A, const Vector& B)
{
return acos(Dot(A, B)/Length(A)/Length(B)); //向量夹角
}
double Cross(const Vector& A, const Vector& B)
{
return A.x*B.y - A.y*B.x; //叉积
}
double Area(const Point& A, const Point& B, const Point& C)
{
return fabs(Cross(B-A, C-A));
}
Vector normal(Vector x)
{
return Point(-x.y, x.x) / Length(x);
}
double angle(Vector x)
{
return atan2(x.y, x.x);
}
Vector vecunit(Vector x)
{
return x / Length(x); //单位向量
}
struct Circle
{
Point c; //圆心
double r; //半径
Circle() { }
Circle(const Circle& rhs): c(rhs.c), r(rhs.r) { }
Circle(const Point& c, const double& r): c(c), r(r) { } Point point(double ang) const
{
return Point(c.x + cos(ang)*r, c.y + sin(ang)*r); //圆心角所对应的点
}
double length(void) const
{
return PI * 2.0 * r;
}
double area(void) const
{
return PI * r * r;
}
void in(void)const
{
scanf("%lf%lf%lf",&c.x,&c.y,&r);
}
};
double CCdistance(Circle a, Circle b)//圆心距
{
return sqrt((a.c.x-b.c.x)*(a.c.x-b.c.x)+(a.c.y-b.c.y)*(a.c.y-b.c.y));
}
int CCguanxi(Circle a,Circle b)//两圆关系
{
double dis=CCdistance(a,b);
if(dis>=a.r+b.r)
return -; //外离||外切
else if(dis<fabs(a.r-b.r))
return ; //内含
else if(fabs(dis-fabs(a.r-b.r))<eps)
return ; //内切
else
return ;//相交
}
double CCyuanxinjiao(Circle a,Circle b) //a,b相交 a的圆心角
{
double dis=CCdistance(a,b);
double temp=(dis*dis+a.r*a.r-b.r*b.r)/(*dis*a.r);
return 2.0*acos(temp);
}
double Arclength(Circle a,double jiaodu) //圆心角所对应的弧长
{
return jiaodu*a.r;
}
Circle c[maxn];
Point p[maxn];
int main()
{
int t;
double r,m;
cin>>t;
while(t--)
{
cin>>m>>r;
Circle yuan(Point(,),r);
double ans=yuan.length();
for(int i=;i<m;i++)
c[i].in();
for(int i=;i<m;i++)
{
//cout<<i<<" "<<c[i].zhouchang()<<endl;
if(CCguanxi(yuan,c[i])==)
ans+=c[i].length();
else if(CCguanxi(yuan,c[i])==)
{
double a=CCyuanxinjiao(yuan,c[i]);
ans-=Arclength(yuan,a);
double b=CCyuanxinjiao(c[i],yuan);
ans+=Arclength(c[i],b);
}
}
printf("%.20f\n",ans);
}
}
HDU 6351暴力枚举 6354计算几何的更多相关文章
- HDU - 5128The E-pang Palace+暴力枚举,计算几何
第一次写计算几何,ac,感动. 不过感觉自己的代码还可以美化一下. 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5128 题意: 在一个坐标系中,有n个 ...
- hdu 4414 暴力枚举
#include <cstdio> #include <cstring> #include <iostream> #include <cmath> #i ...
- HDU:3368-Reversi(暴力枚举)
Reversi Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...
- HDU 6638 - Snowy Smile 线段树区间合并+暴力枚举
HDU 6638 - Snowy Smile 题意 给你\(n\)个点的坐标\((x,\ y)\)和对应的权值\(w\),让你找到一个矩形,使这个矩阵里面点的权值总和最大. 思路 先离散化纵坐标\(y ...
- hdu 1172 猜数字(暴力枚举)
题目 这是一道可以暴力枚举的水题. //以下两个都可以ac,其实差不多一样,呵呵 //1: //4 wei shu #include<stdio.h> struct tt { ],b[], ...
- BestCoder Round #50 (div.1) 1002 Run (HDU OJ 5365) 暴力枚举+正多边形判定
题目:Click here 题意:给你n个点,有多少个正多边形(3,4,5,6). 分析:整点是不能构成正五边形和正三边形和正六边形的,所以只需暴力枚举四个点判断是否是正四边形即可. #include ...
- hdu 4445 Crazy Tank (暴力枚举)
Crazy Tank Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU - 1248 寒冰王座 数学or暴力枚举
思路: 1.暴力枚举每种面值的张数,将可以花光的钱记录下来.每次判断n是否能够用光,能则输出0,不能则向更少金额寻找是否有能够花光的.时间复杂度O(n) 2.350 = 200 + 150,买350的 ...
- HDU 6351 (带技巧的暴力)
题意:给定一个数,和一个最多交换次数k,问在不超过k次操作的情况,问可以得到的最大值和最小值是多少? 个人解题的艰辛路程 , 开始是想到了暴力枚举的可能 , 打出来发现在判断枚举的数组与原来数组交换了 ...
随机推荐
- web前端开发总结(未完)
由于我也是接触前端开发不久,所以呢,自己也会做点小功课,于是,我把前端能够用到的知识稍稍做了下总结,总结的不全面,以后会慢慢完善的! 移动前端开发基础 (总结----待完善)1.移动前端开发:简而言之 ...
- 《移动App性能评测与优化》读书笔记
第一章:内存 内存的主要组成索引: Native Heap:Native代码分配的内存,虚拟机和Android框架本身也会分配 Dalvik Heap:Java代码分配的对象 Dalvik Oth ...
- Python+Selenium框架设计篇之-什么是POM
前面我们介绍了Python中的单元测试框架unittest,以后我们所有的测试类文件,都采用unittest来辅助我们进行debug和脚本开发.搞定了debug机制和确定了unittest来进行创建和 ...
- python multiprocessing.Pool 中map、map_async、apply、apply_async的区别
multiprocessing是python的多进程库,multiprocessing.dummy则是多线程的版本,使用都一样. 其中都有pool池的概念,进程池/线程池有共同的方法,其中方法对比如下 ...
- CentOS 6.3安装配置LAMP服务器(Linux+Apache+MySQL+PHP5)
服务器系统环境:CentOS 6.3 客户端系统环境:Windows 7 ultimate(x86)sp1 简体中文旗舰版 ※ 本文档描述了如何在Linux服务器配置Apache.Mysql.PHP ...
- css深入理解relative
第一讲 relative和absolute相煎关系 同源性 .position:relative .position:absolute 限制作用 1.限制left/top/right/bott ...
- Android记事本开发01
今天: 学习一下Android的基本知识,了解一下记事本开发大概需要哪些知识. 昨天: 无 遇到的问题:
- GDI+实现双缓冲绘图方法一
private void Form5_MouseMove(object sender, MouseEventArgs e) { int intOX = rectDrawArea.X; int intO ...
- vue cli & vue 3.x
vue cli & vue 3.x https://cli.vuejs.org/dev-guide/ui-api.html#ui-api https://cli.vuejs.org/zh/gu ...
- hdu 1242 Rescue (BFS)
Rescue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...