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次操作的情况,问可以得到的最大值和最小值是多少? 个人解题的艰辛路程 , 开始是想到了暴力枚举的可能 , 打出来发现在判断枚举的数组与原来数组交换了 ...
随机推荐
- Visual Studio使用技巧笔记(引用程序集自动复制dll到引用项目目录)
copy /y $(TargetPath) $(SolutionDir)\[您项目引用dll文件的目录]\$(TargetFileName) 例如:copy /y $(TargetPath) $(So ...
- js 请求异常重连或断线后联网重连机制(ajax)
转到到 https://blog.csdn.net/mengtoumingren/article/details/80296788
- mysql用root账户建立用户和赋予权限
1.创建用户 create user guest_test@localhost identified by "root";-- 创建名为guest_test的用户 2.赋予权限 - ...
- [译]16-spring基于注解的配置元数据
从spring2.5起spring框架开始支持java注解的配置元数据.所以除了使用xml配置文件来描述bean的装配之外,你还 可以使用基于java注解的配置元数据来完成同样的功能. spring框 ...
- 自动using和Layout
一.自动using 1. Model 文件夹添加 Person类,在view文件夹下web.config文件,将namespace加入,cshtml文件就不需要添加@model引用: ...
- Python全栈工程师(元组、字典)
ParisGabriel 感谢 大家的支持 你们的阅读评价就是我最好的更新动力 我会坚持吧排版做的越来越好 每天坚持 一天一篇 点个订阅吧 灰常感谢 当个死粉也阔以 ...
- HDU 4667 Building Fence 计算几何 凸包+圆
1.三角形的所有端点 2.过所有三角形的端点对所有圆做切线,得到所有切点. 3.做任意两圆的外公切线,得到所有切点. 对上述所有点求凸包,标记每个点是三角形上的点还是某个圆上的点. 求完凸包后,因为所 ...
- chrome浏览器console拓展用法
chrome 浏览器console打印 使用CSS美化输出信息 console.log("%cThis will be formatted with large, blue text&quo ...
- Git 提交修改
今天发现前几天的某一个提交因为忽略文件的问题而导致有几个文件没有提交,需要修改一下某个提交,研究一下可以用rebase命令来完成,执行过程模拟如下: 1. 环境搭建,版本库如下: 文件目录如下: 假设 ...
- Zigzag数组 -- 面试宝典
最近在看面试宝典,其中看到一个题目说:输入一个正整数n,输出它的zigzag数组. 分析:书上给出了数学方面的思考然后给了代码.但是我感觉如果真是面试或者考试遇到的话,我这种笨脑袋肯定是想不出来的,因 ...