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次操作的情况,问可以得到的最大值和最小值是多少? 个人解题的艰辛路程 , 开始是想到了暴力枚举的可能 , 打出来发现在判断枚举的数组与原来数组交换了 ...
随机推荐
- ITIBB原创,互联网首部自媒体小说《1024伐木累》-小白篇之入职-总章节一
小序 IT人不懂爱?代码汪是小白?又有谁,懂我情怀? 逗比青年,背上行囊,懵懵懂懂闯帝都!前途似海,来日方长! 青春无梦妄少年!认定就作,不平就说,碰撞火花,如此绚烂…… IT人有比格?其实,那是顽强 ...
- 【Remove Duplicates from Sorted List 】cpp
题目: 第一次刷的时候漏掉了这道题. Given a sorted linked list, delete all duplicates such that each element appear o ...
- Python面试题之一:解密
Python面试题之一: 说明:就是Python工程师面试题 一.字典转换与正则提取值 1:key与Value交换 a = {'a':1,'b':2} print({value:key for key ...
- Vue_自定义指令
关于Vue的自定义指令: - 在Vue中除了核心功能默认内置的指令(v-model & v-show) - Vue也允许注册自定义指令. 注意,在 Vue2.0 中,代码复用和抽象的主要形式是 ...
- 九宫重排_康拓展开_bfs
历届试题 九宫重排 时间限制:1.0s 内存限制:256.0MB 问题描述 如下面第一个图的九宫格中,放着 1~8 的数字卡片,还有一个格子空着.与空格子相邻的格子中的卡片可 ...
- 清除浮动float (:after方法)
1. 什么时候需要清除浮动?清除浮动有哪些方法? (1)对元素进行了浮动(float)后,该元素就会脱离文档流,浮动在文档之上.在CSS中,任何元素都可以浮动.浮动元素会生成一个块级框,而不论它本身是 ...
- hdu 2510 符号三角形 (DFS+打表)
符号三角形 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- BZOJ4826 [Hnoi2017]影魔 【线段树 + 单调栈】
题目链接 BZOJ4826 题解 蒟蒻智力水平捉急orz 我们会发现相邻的\(i\)和\(j\)贡献一定是\(p1\),可以很快算出来[然而我一开始忘了考虑调了半天] 我们现在只考虑不相邻的 我们只需 ...
- 洛谷 P2173 [ZJOI2012]网络 解题报告
P2173 [ZJOI2012]网络 题目描述 有一个无向图G,每个点有个权值,每条边有一个颜色.这个无向图满足以下两个条件: 对于任意节点连出去的边中,相同颜色的边不超过两条. 图中不存在同色的环, ...
- Numpy基本数据结构
Numpy数组是一个多维数组对象,称为ndarray.其由两部分组成: 1 实际的数据 2 描述这些数据的元数据 一 ndarray的方法 # 多维数组ndarray import numpy as ...