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


Problem Description
Anton has a positive integer n, however, it quite looks like a mess, so he wants to make it beautiful after k swaps of digits.
Let the decimal representation of n as (x1x2xm)10 satisfying that 1x190xi9 (2im), which means n=mi=1xi10mi. In each swap, Anton can select two digits xi and xj (1ijm) 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?
 

 

Input
The first line contains one integer T, indicating the number of test cases.
Each of the following T lines describes a test case and contains two space-separated integers n and k.
1T1001n,k109.
 

 

Output
For each test case, print in one line the minimum integer and the maximum integer which are separated by one space.
 

 

Sample Input
5
12 1
213 2
998244353 1
998244353 2
998244353 3
 
Sample Output
12 21
123 321
298944353 998544323
238944359 998544332
233944859 998544332
 
解析 暴力枚举交换1-min(len-1,k) 次的下标排列情况的   算出每种情况的值   感觉有点超时啊  9!*T*10  每种情况都要除10下分解掉 明明是3e8啊 2.5s很悬啊
 
AC代码
#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+50,inf=1e18;
const ll mod=1e9+7;
vector<int> per[10][10];
int vis[11],a[10],b[10];
void init()
{
    for(int i=1;i<=9;i++)
    {
        for(int j=1;j<=i;j++)
            a[j]=j;
        do
        {
            fillchar(vis,0);
            int now=0,temp=0;
            for(int j=1;j<=i;j++)
                now=now*10+a[j];
            for(int j=1;j<=i;j++)
            {
                if(vis[j]==0)
                {
                    vis[j]=1;
                    for(int k=a[j];k!=j;k=a[k])
                        vis[k]=1,temp++;
                }
            }
            per[i][temp].pb(now);
        }while(next_permutation(a+1,a+i+1));
    }
}
char s[12];
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==10)
        {
            printf("%d %d\n",minn,maxx);
            continue;
        }
        reverse(s,s+len);
        if(len<=k)k=len-1;
        for(int i=0;i<=k;i++)
        {
            for(int j=0;j<per[len][i].size();j++)
            {
                int temp=per[len][i][j],cnt=0,sum=0;
                while(temp)
                {
                   sum=sum*10+int(s[temp%10-1]-'0');
                   temp/=10;
                }
                //cout<<per[len][i][j]<<" "<<sum<<endl;
                if((int)pow(10,len-1)>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

解析 内切的直接把周长加起来  相交的减去原来的弧长 加上另一个圆的弧长  根据余弦定理可以算出来角度  角度*半径就是弧长了

  1 #include <bits/stdc++.h>
  2 #define LL long long
  3 #define PI 3.1415926535897932384626
  4 #define maxn 1000
  5 #define EXIT exit(0);
  6 #define DEBUG puts("Here is a BUG");
  7 #define CLEAR(name, init) memset(name, init, sizeof(name))
  8 const double eps = 1e-9;
  9 const int MAXN = (int)1e9 + 5;
 10 using namespace std;
 11 #define Vector Point
 12 int dcmp(double x)
 13 {
 14     return fabs(x) < eps ? 0 : (x < 0 ? -1 : 1);
 15 }
 16 struct Point
 17 {
 18     double x, y;
 19 
 20     Point(const Point& rhs): x(rhs.x), y(rhs.y) { } //拷贝构造函数
 21     Point(double x = 0.0, double y = 0.0): x(x), y(y) { }   //构造函数
 22     friend istream& operator >> (istream& in, Point& P)
 23     {
 24         return in >> P.x >> P.y;
 25     }
 26     friend ostream& operator << (ostream& out, const Point& P)
 27     {
 28         return out << P.x << ' ' << P.y;
 29     }
 30     friend Vector operator + (const Vector& A, const Vector& B)
 31     {
 32         return Vector(A.x+B.x, A.y+B.y);
 33     }
 34     friend Vector operator - (const Point& A, const Point& B)
 35     {
 36         return Vector(A.x-B.x, A.y-B.y);
 37     }
 38     friend Vector operator * (const Vector& A, const double& p)
 39     {
 40         return Vector(A.x*p, A.y*p);
 41     }
 42     friend Vector operator / (const Vector& A, const double& p)
 43     {
 44         return Vector(A.x/p, A.y/p);
 45     }
 46     friend bool operator == (const Point& A, const Point& B)
 47     {
 48         return dcmp(A.x-B.x) == 0 && dcmp(A.y-B.y) == 0;
 49     }
 50     friend bool operator < (const Point& A, const Point& B)
 51     {
 52         return A.x < B.x || (A.x == B.x && A.y < B.y);
 53     }
 54     void in(void)
 55     {
 56         scanf("%lf%lf", &x, &y);
 57     }
 58     void out(void)
 59     {
 60         printf("%lf %lf", x, y);
 61     }
 62 };
 63 template <class T> T sqr(T x)
 64 {
 65     return x * x;
 66 }
 67 double Dot(const Vector& A, const Vector& B)
 68 {
 69     return A.x*B.x + A.y*B.y;    //点积
 70 }
 71 double Length(const Vector& A)
 72 {
 73     return sqrt(Dot(A, A));
 74 }
 75 double Angle(const Vector& A, const Vector& B)
 76 {
 77     return acos(Dot(A, B)/Length(A)/Length(B));    //向量夹角
 78 }
 79 double Cross(const Vector& A, const Vector& B)
 80 {
 81     return A.x*B.y - A.y*B.x;    //叉积
 82 }
 83 double Area(const Point& A, const Point& B, const Point& C)
 84 {
 85     return fabs(Cross(B-A, C-A));
 86 }
 87 Vector normal(Vector x)
 88 {
 89     return Point(-x.y, x.x) / Length(x);
 90 }
 91 double angle(Vector x)
 92 {
 93     return atan2(x.y, x.x);
 94 }
 95 Vector vecunit(Vector x)
 96 {
 97     return x / Length(x);   //单位向量
 98 }
 99 struct Circle
100 {
101     Point c;    //圆心
102     double r;   //半径
103     Circle() { }
104     Circle(const Circle& rhs): c(rhs.c), r(rhs.r) { }
105     Circle(const Point& c, const double& r): c(c), r(r) { }
106 
107     Point point(double ang) const
108     {
109         return Point(c.x + cos(ang)*r, c.y + sin(ang)*r);    //圆心角所对应的点
110     }
111     double length(void) const
112     {
113         return PI * 2.0 * r;
114     }
115     double area(void) const
116     {
117         return PI * r * r;
118     }
119     void in(void)const
120     {
121         scanf("%lf%lf%lf",&c.x,&c.y,&r);
122     }
123 };
124 double CCdistance(Circle a, Circle b)//圆心距
125 {
126     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));
127 }
128 int CCguanxi(Circle a,Circle b)//两圆关系
129 {
130     double dis=CCdistance(a,b);
131     if(dis>=a.r+b.r)
132         return -1;  //外离||外切
133     else if(dis<fabs(a.r-b.r))
134         return 0;   //内含
135     else if(fabs(dis-fabs(a.r-b.r))<eps)
136         return 2; //内切
137     else
138         return 1;//相交
139 }
140 double CCyuanxinjiao(Circle a,Circle b) //a,b相交 a的圆心角
141 {
142     double dis=CCdistance(a,b);
143     double temp=(dis*dis+a.r*a.r-b.r*b.r)/(2*dis*a.r);
144     return 2.0*acos(temp);
145 }
146 double Arclength(Circle a,double jiaodu) //圆心角所对应的弧长
147 {
148     return jiaodu*a.r;
149 }
150 Circle c[maxn];
151 Point p[maxn];
152 int main()
153 {
154     int t;
155     double r,m;
156     cin>>t;
157     while(t--)
158     {
159         cin>>m>>r;
160         Circle yuan(Point(0,0),r);
161         double ans=yuan.length();
162         for(int i=0;i<m;i++)
163             c[i].in();
164         for(int i=0;i<m;i++)
165         {
166             //cout<<i<<" "<<c[i].zhouchang()<<endl;
167             if(CCguanxi(yuan,c[i])==2)
168                 ans+=c[i].length();
169             else if(CCguanxi(yuan,c[i])==1)
170             {
171                 double a=CCyuanxinjiao(yuan,c[i]);
172                 ans-=Arclength(yuan,a);
173                 double b=CCyuanxinjiao(c[i],yuan);
174                 ans+=Arclength(c[i],b);
175             }
176         }
177         printf("%.20f\n",ans);
178     }
179 }
View Code

 

posted @ 2018-08-07 16:45  灬从此以后灬  阅读(209)  评论(0编辑  收藏  举报