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次操作的情况,问可以得到的最大值和最小值是多少? 个人解题的艰辛路程 , 开始是想到了暴力枚举的可能 , 打出来发现在判断枚举的数组与原来数组交换了 ...
随机推荐
- 玩转Linux之内存管理-free
玩转Linux之内存管理-free free命令可以显示Linux系统中空闲的.已用的物理内存及swap内存,及被内核使用的buffer.在Linux系统监控的工具中,free命令是最经常使用的命令之 ...
- 【Dual Support Vector Machine】林轩田机器学习技法
这节课内容介绍了SVM的核心. 首先,既然SVM都可以转化为二次规划问题了,为啥还有有Dual啥的呢?原因如下: 如果x进行non-linear transform后,二次规划算法需要面对的是d`+1 ...
- Linux忘记root密码的解决办法
这里以centos6为例: 第一步:先将系统重新启动,在读秒的时候按下任意键就会出现如下图的菜单界面: 第二步:按下『e』就能够进入grub的编辑模式,如图: 第三步:将光标移动到kernel那一行, ...
- [转]unity之LOD
LOD技术有点类似于Mipmap技术,不同的是,LOD是对模型建立了一个模型金字塔,根据摄像机距离对象的远近,选择使用不同精度的模型. 它的好处是可以在适当的时候大量减少需要绘制的顶点数目. 它的缺点 ...
- iPhone新建项目不能全屏
上个周做项目的时候,发现新建了一个项目不能全屏.伤透了我的脑筋,然后又请教了团队里其他两个大牛帮我搞定了这个问题. 虽然是搞定了,但也看的出大牛也是云里雾里.歪打正着解决的. 今天又想新做个项目,这个 ...
- FormsAuthentication类
理解代码: string cookieName = FormsAuthentication.FormsCookieName; FormsAuthentication类说明: // 摘要: // 为 W ...
- 第一次使用iptables
sudo iptables -A OUTPUT -m cgroup ! --cgroup 0x100001 -j DROP 第一次使用iptables就把电脑弄得上不了网了...... 下面这个地址讲 ...
- 【bzoj2959】长跑 LCT+并查集
题目描述 某校开展了同学们喜闻乐见的阳光长跑活动.为了能“为祖国健康工作五十年”,同学们纷纷离开寝室,离开教室,离开实验室,到操场参加3000米长跑运动.一时间操场上熙熙攘攘,摩肩接踵,盛况空前.为了 ...
- C#类和类成员初始化顺序
1.不带静态成员的普通类,首先通过构造函数初始化. 2.带静态属性的类,无论是普通类还是静态类,都会先初始化静态字段,再执行构造函数. 3.类初始化时,不会执行类中方法,无论是否是静态.若想执行方法, ...
- 结构型设计模式之桥接模式(Bridge)
结构 意图 将抽象部分与它的实现部分分离,使它们都可以独立地变化. 适用性 你不希望在抽象和它的实现部分之间有一个固定的绑定关系.例如这种情况可能是因为,在程序运行时刻实现部分应可以被选择或者切换. ...