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次操作的情况,问可以得到的最大值和最小值是多少? 个人解题的艰辛路程 , 开始是想到了暴力枚举的可能 , 打出来发现在判断枚举的数组与原来数组交换了 ...
随机推荐
- 起始授权机构(SOA)
起始授权机构 编辑 本词条缺少名片图,补充相关内容使词条更完整,还能快速升级,赶紧来编辑吧! 起始授权机构,SOA(Start Of Authority):该记录表明DNS名称服务器是DNS域中的数据 ...
- 剑指Offer - 九度1354 - 和为S的连续正数序列
剑指Offer - 九度1354 - 和为S的连续正数序列2013-11-23 02:02 题目描述: 小明很喜欢数学,有一天他在做数学作业时,要求计算出9~16的和,他马上就写出了正确答案是100. ...
- DOS程序员手册(十二)
DOS可安全使用 610页 在DOS控制台I/O操作进行轮询循环时,有规律地调用中断,以便允许终止 并驻留(TSR)程序(如适用于DOS的实用程序PRINT.COM),知道它可安全 地使用文件操作和其 ...
- 24、php知识点总结基础教程--part-2
1.表单处理 ①post请求 <html> <body> <form action="welcome.php" method="post&q ...
- postman与charles的结合使用
1.准备charles环境 Charles端口一般配置的为8888,不知道怎么配置详见charles文档 打开charles,发现访问浏览器任意页面都是失败. 在浏览器的高级设置中设置代理服务器,以火 ...
- 你的第一个自动化测试:Appium 自动化测试
前言: 这是让你掌握 App 自动化的文章 一.前期准备 本文版权归作者和博客园共有,原创作者:http://www.cnblogs.com/BenLam,未经作者同意必须在文章页面给出原文连接. 1 ...
- coreos ipa image Injection of public key
查看readme To embed the oem/ directory into a CoreOS pxe image: Note: In order to have the ability t ...
- BATCH梯度下降,单变量线性回归
- 关于CPU位数,OS位数以及内存大小关系的一点总结
(这个学期做助教,说来好惭愧啊,虽然我也是考研进来的,但是就在两年前复习的资料居然全部都忘光了.对大二的孩子们提问的问题多半都解决不了!!!越来越觉得自己的学习方法有问题了,总是想着一些知识能够根据自 ...
- 测试计划驱动开发模式 TPDD:一种比 TDD 更友好的开发模式
相信大部分开发团队都在使用TDD,并且还有很多开发团队都 对外声明 在使用 TDD 开发模式. 之所以说是“对外声明”,是因为很多开发团队虽然号称使用的是 TDD 开发模式,实际开发过程中却无法满足 ...