wall

                

 Wall

Once upon a time there was a greedy King who ordered his chief Architect to build a wall around the King's castle. The King was so greedy, that he would not listen to his Architect's proposals to build a beautiful brick wall with a perfect shape and nice tall towers. Instead, he ordered to build the wall around the whole castle using the least amount of stone and labor, but demanded that the wall should not come closer to the castle than a certain distance. If the King finds that the Architect has used more resources to build the wall than it was absolutely necessary to satisfy those requirements, then the Architect will loose his head. Moreover, he demanded Architect to introduce at once a plan of the wall listing the exact amount of resources that are needed to build the wall.


Your task is to help poor Architect to save his head, by writing a program that will find the minimum possible length of the wall that he could build around the castle to satisfy King's requirements.

The task is somewhat simplified by the fact, that the King's castle has a polygonal shape and is situated on a flat ground. The Architect has already established a Cartesian coordinate system and has precisely measured the coordinates of all castle's vertices in feet.

输入

The first line of the input file contains two integer numbers N and L separated by a space. N (3 <= N <= 1000) is the number of vertices in the King's castle, and L (1 <= L <= 1000) is the minimal number of feet that King allows for the wall to come close to the castle.

Next N lines describe coordinates of castle's vertices in a clockwise order. Each line contains two integer numbers Xi and Yi separated by a space (-10000 <= Xi, Yi <= 10000) that represent the coordinates of ith vertex. All vertices are different and the sides of the castle do not intersect anywhere except for vertices.

输出

Write to the output file the single number that represents the minimal possible length of the wall in feet that could be built around the castle to satisfy King's requirements. You must present the integer number of feet to the King, because the floating numbers are not invented yet. However, you must round the result in such a way, that it is accurate to 8 inches (1 foot is equal to 12 inches), since the King will not tolerate larger error in the estimates.

样例输入

9 100
200 400
300 400
300 300
400 300
400 400
500 400
500 200
350 200
200 200

样例输出

1628

题意: 给定n个点,L为圆半径,求n个点组成的凸包长度加上圆的长度

思路 : 直接跑Andrew复杂都为nlogn开销为排序所花,其中出栈入栈最多4*n

实现方式

#include<bits/stdc++.h>
using namespace std;
const int N =1e5+10;
const int M =400+10;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>PII;
#define pb push_back
//__builtin_popcountll(x) 二进制 1 个数
const ll mod = 998244353;
int n,m,k,r;
struct node{
    double x,y;
    friend bool operator < (node x,node y){
        return x.x != y.x ? x.x < y.x : x.y<y.y;
    }
}a[N],st[N];//stcak
double cross(node x,node y,node z){//x1y2 - x2y1
    return (y.x-x.x)*(z.y-x.y) - (z.x-x.x)*(y.y-x.y);
}
double get_len(node x,node y){
    return sqrt((x.x-y.x)*(x.x-y.x) + (x.y-y.y)*(x.y-y.y));
}
void solve(){
    for(int i=1;i<=n;i++) cin>>a[i].x>>a[i].y;
    sort(a+1,a+1+n);
    int top=0;
    for(int i=1;i<=n;i++){
        while(top>1&&cross(st[top-1], st[top],a[i])<=0) --top;
        st[++top] = a[i];
    }
    int idx = top;
    for(int i=n-1;i>=1;i--)// n  在stack中了没必要枚举
    {
        while(top>idx&&cross(st[top-1], st[top],a[i])<=0) --top;
        st[++top] = a[i];
    }
    double ans = 2.0*acos(-1)*r;// area of circle
    for(int i=1;i<top;i++)// 上凸包最后会与原点重合
    ans+=get_len(st[i], st[i+1]);
//    printf("%.0f\n",ans);
    cout<<floor(ans+0.5)<<'\n';// 上取整
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int T=1;
//      cin>>T;
    while(cin >>n>>r){
        solve();
    }
    return 0;
}
//2
//4
//1 3 2 4
//2
//2 1

矩阵游戏 

婷婷是个喜欢矩阵的小朋友,有一天她想用电脑生成一个巨大的n行m列的矩阵(你不用担心她如何存储)。她生成的这个矩阵满足一个神奇的性质:若用F[i][j]来表示矩阵中第i行第j列的元素,则F[i][j]满足下面的递推式:


F[1][1]=1
F[i,j]=a*F[i][j-1]+b (j!=1)
F[i,1]=c*F[i-1][m]+d (i!=1)
递推式中a,b,c,d都是给定的常数。

现在婷婷想知道F[n][m]的值是多少,请你帮助她。由于最终结果可能很大,你只需要输出F[n][m]除以1,000,000,007的余数。

输入

一行有六个整数n,m,a,b,c,d。意义如题所述。

1<=N,M<=10^1000 000,a<=a,b,c,d<=10^9

输出

包含一个整数,表示F[n][m]除以1,000,000,007的余数

样例输入

        3 4 1 3 2 6

样例输出

        85

提示

样例中的矩阵为:

1 4 7 10
26 29 32 35
76 79 82 85

因为n,m很大,可以通过欧拉函数降次,或者费马小定理来降次数

m−1≡1(mod m), 因为涉及到矩阵的n次跑矩阵快速幂加速一下过程;

初始化一下矩阵

#include<bits/stdc++.h>
using namespace std;
const int N =1e5+10;
const int M =400+10;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>PII;
#define pb push_back
//__builtin_popcountll(x) 二进制 1 个数
#define int ll
const ll mod = 1e9+7;
int n=0,m=0,k,r;
struct matrix{
    int a[5][5];
    matrix(){
        memset(a,0,sizeof a);
    }
    int *operator [](int x){
        return a[x];
    }
}A,B,C,D,E,F,G;
matrix operator *(const matrix &A,const matrix &B){
    matrix now;
    for(int i=1;i<=2;i++)
        for(int j=1;j<=2;j++)
             for(int k=1;k<=2;k++)
                  (now[i][j] += A.a[i][k]*B.a[k][j])%=mod;
    
    return now;
}
void solve(){
    string s,s1;
    int a,b,c,d;
    cin>>s>>s1>>a>>b>>c>>d;
    for(int i=0;i<s.size();i++) 
    n=(n*10+s[i]-'0')%(a==1?mod:mod-1);//费马小定理
    for(int i=0;i<s1.size();i++) 
    m=(m*10+s1[i]-'0')%(a==1?mod:mod-1);//费马小定理
    n--,m--;
    G[1][1] = G[1][2] = 1;//  初始矩阵 
    A[1][1] = a, A[2][1] = b,A[2][2] = 1;
    C[1][1] = c, C[2][1] = d,C[2][2] = 1;
    B[1][1] = B[2][2] = D[1][1] = D[2][2]= 1;// 单位阵
    while(m){//快速幂
        if(m&1)B=B*A;
        A=A*A;
        m>>=1;
    }
    E=C*B;
    for(int i=1;i<=2;i++)D[i][i]=1;
    while(n){//快速幂
        if(n&1)D=D*E;
        E=E*E;
        n>>=1;
    }
    F=B*D;
    G=G*F;
    cout<<G[1][1]<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int T=1;
//    cin>>T;
    while(T--){
        solve();
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值