拖拖拖了好久的校賽補題nefu1259&nefu1260&nefu1261&nefu1262&nefu1263&nefu1264

NEFU1259

題目:

還記得矩陣快速冪嗎?給出如下遞推方程:f(n)=f(n-1)+2^(n-1) 其中 f(1)=1,求 f(n)
快速冪模板題(一開始居然想用遞歸真是腦子燒壞了)
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll quickmod(ll m,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1)
            ans=ans*m%mod;
        m=m*m%mod;
        n>>=1;
    }
    return ans%mod;
}
int main()
{
    ll t,n;
    while(cin>>t)
    {
        while(t--)
        {
            cin>>n;
            cout<<(quickmod(2,n)-1)%mod<<endl;
        }
    }
    return 0;
}

NEFU1260

題目

給定f(n)=n^a+n^(a+1)+...+n^(b-1)+n^b求f(n)%MOD
需要用到快速乘法(模比較大)和注意特判n

#include <iostream>
using namespace std;
typedef long long ll;
const ll mod=10000000033;
ll cf(ll b,ll m)
{
    ll ans=0;
    while(m)
    {
        if(m&1)
          ans=(ans+b)%mod;
           b=(b+b)%mod;
        m/=2;

    }
    return ans;
}
ll quickmod(ll m,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1)
            ans=cf(ans,m)%mod;
            n/=2;
           m=cf(m,m)%mod;
    }
    return ans%mod;
}
int main()
{
        ll t,a,b,n;
           cin>>t;
        while(t--)
        {
            cin>>a>>b>>n;
            ll ans=0;
            if(a>b)
               swap(a,b);
        if(n==1)
            ans=b-a+1;
        else if(n==0)
             ans=0;
        else
            ans=cf((quickmod(n,b+1)-quickmod(n,a)+mod)%mod,quickmod(n-1,mod-2))%mod;
          //  cout<<quickmod(n,b+1)-quickmod(n,a)+mod<<endl;
       //     cout<<quickmod(n,b+1)<<" "<<quickmod(n,a)<<endl;
         //   cout<<quickmod(n-1,mod-2)<<endl;
            cout<<ans%mod<<endl;
   }
    return 0;
}
NEFU1261

題目

給定空間4個點的座標(x,y,z),求這四個點圍成的圖形的體積,結果保留兩位小數
公式題,發現了體積的海倫公式但是沒過,用的別的公式(求大佬看看類海倫公式咋錯了)
//類海倫公式
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
typedef struct node
{
    double x,y,z;
}ss;

double dis(node a,node b)
{
   return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z));
}
int main()
{
    int t;cin>>t;
    while(t--)
    {
        ss tt[5];
        cin>>tt[0].x>>tt[0].y>>tt[0].z;
           cin>>tt[1].x>>tt[1].y>>tt[1].z;
              cin>>tt[2].x>>tt[2].y>>tt[2].z;
                 cin>>tt[3].x>>tt[3].y>>tt[3].z;
                 double a,b,c,j,k,l;
                 c=dis(tt[0],tt[1]);
                 a=dis(tt[0],tt[2]);
                 b=dis(tt[0],tt[3]);
                 j=dis(tt[1],tt[3]);
                 k=dis(tt[1],tt[2]);
                 l=dis(tt[2],tt[3]);
                 double f,g,t;
                 f=acos((a*a+c*c-k*k)/(2*a*c));
                 g=acos((b*b+c*c-j*j)/(2*b*c));
                 t=acos((b*b+a*a-l*l)/(2*b*a));
               //  cout<<f<<g<<t<<endl;
                double p=(f+g+t)/2;
            
                double s=sqrt(fabs(sin(p)*sin(p-f)*sin(p-g)*sin(p-t)));
             
                double v=a*b*c*s*1/3;
                printf("%.2lf\n",v);
    }
    return 0;
}
//AC代碼
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
typedef struct node
{
    double x,y,z;
}ss;
double dis(node a,node b)
{
   return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z);
}
int main()
{
    int t;cin>>t;
    while(t--)
    {
        ss tt[5];
        cin>>tt[0].x>>tt[0].y>>tt[0].z;
           cin>>tt[1].x>>tt[1].y>>tt[1].z;
              cin>>tt[2].x>>tt[2].y>>tt[2].z;
                 cin>>tt[3].x>>tt[3].y>>tt[3].z;
               double a,b,c,d,e,f;
                 a=dis(tt[0],tt[1]);
                 b=dis(tt[0],tt[2]);
                 c=dis(tt[0],tt[3]);
                 e=dis(tt[1],tt[3]);
                 f=dis(tt[1],tt[2]);
                 d=dis(tt[2],tt[3]);

          /*double f,g,t;
                 f=acos((a*a+c*c-k*k)/(2*a*c));
                 g=acos((b*b+c*c-j*j)/(2*b*c));
                 t=acos((b*b+a*a-l*l)/(2*b*a));
               //  cout<<f<<g<<t<<endl;
            double p=(f+g+t)/2;
              double s=sqrt(fabs(sin(p)*sin(p-f)*sin(p-g)*sin(p-t)));
            double v=a*b*c*s*1/3;*/
            double v=sqrt(a*d*(b+c+e+f-a-d)+b*e*(a+c+d+f-b-e)+c*f*(a+b+d+e-c-f)-a*b*f-b*c*d-c*a*e-d*e*f)/12;
                printf("%.2lf\n",v);
    }
    return 0;
}

NEFU1262

題目

求一個數的因子和
模板題(but最後x>1出了問題)

#include <iostream>
#include <string.h>
using namespace std;
typedef long long ll;
int prime[1000005];
int vis[1000005],cnt;
void init()
{
    cnt=0;
    memset(vis,0,sizeof(vis));
    for(int i=2; i<50005; i++)
    {
        if(!vis[i])
        {
            prime[cnt++]=i;
            for(int j=i+i; j<50005; j+=i)
                vis[j]=1;
        }
    }
}
ll cf(ll b,ll m, ll tt)
{
    ll ans=0;
    while(m)
    {
        if(m&1)
            ans=(ans+b)%tt;
        m>>=1;
        b=(b+b)%tt;
    }
    return ans;
}
ll quick(ll m,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1)
            ans=ans*m;
        m=m*m;
        n>>=1;
    }
    return ans;
}
int main()
{
    ll t,a;
    init();
    while(cin>>t)
    {
        while(t--)
        {
            cin>>a;
            ll ans=1;
            ll x=a;
            for(int i=0; i<cnt; i++)
            {
                if(a%prime[i]==0)
                {
                    ll tmp=0;
                    while(x%prime[i]==0)
                    {
                        tmp++;
                        x/=prime[i];
                    }
                    ans*=(quick(prime[i],tmp+1)-1)/(prime[i]-1);
                }
            }
            if(x>1)
               {
                   ans=ans+ans*x;
               }

            cout<<ans<<endl;
        }
    }

    return 0;
}
NEFU1263

題目

BD有最近在玩一個遊戲,當然玩遊戲肯定需要很多遊戲幣,某公司最新推出了一款新型的遊戲幣,這款新型遊戲幣有 n 種幣值,其中幣值爲v_i的有 w_i 個,現在BD手裏只有一個 x 元的遊戲幣,爲了方便,她想換成零錢,問有多少種方案?
母函數模板題

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
#define MAX 100
int v[55],n2[55],n1[55];
int main()
{
    int  t;
    cin>>t;
    while(t--)
    {
        int n,P;
        cin>>n;
        for(int i=0; i<n; i++)
        {
             cin>>v[i]>>n2[i];
             n1[i]=0;
        }

        cin>>P;
        int a[MAX],b[MAX];
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        a[0]=1;
        for (int i=0; i<n; i++)
        {
            memset(b,0,sizeof(b));
            for (int j=n1[i]; j<=n2[i]&&j*v[i]<=P; j++)
                for (int k=0; k+j*v[i]<=P; k++)
                    b[k+j*v[i]]+=a[k];
            memcpy(a,b,sizeof(b));
        }
        int ans=0;

        cout<<a[P]<<endl;
    }

    return 0;
}

NEFU1264

題目

平面上有n個點,每個點有各自的速度向量,現在給出0時刻,在同一時刻,平面點的最遠距離叫做special dis他們每個點的位置和每個點的速度向量,現在求在哪個時刻的時候,他們的special dis 最小,並輸出這個距離。
求最大的最小用三分。。暴力TLE

//TLE
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
 int t,n;

typedef struct node
{
    double x,y,vx,vy;

}tt;
tt s[10005];
double dis(node a,node b,double t)
{
   double x1=a.x+t*a.vx;
   double y1=a.y+t*a.vy;
   double x2=b.x+t*b.vx;
   double y2=b.y+t*b.vy;
     double xx=x1-x2;
     double yy=y1-y2;
     double dis=pow(pow(xx,2)+pow(yy,2),0.5);
     return dis;
}
double calc(double t)
{
    double maxn=0.0;
    for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++)
    {
        double disn=dis(s[i],s[j],t);
        maxn=max(maxn,disn);
    }
    return maxn;
}

void solve()
{
      double L=0.0,R=200000,M;
      double RM=0,LM;
     while(R-L>0.01)
     {

           M = (L + R) / 2;
        LM = (M + L) / 2;
        RM=LM+0.001;
        if (calc(LM) < calc(RM)) R = LM;
        else L = LM;
     }
     printf("%.2lf %.2lf\n",LM,calc(LM));
     // cout<<LM<<" "<<calc(LM)<<endl;
   // return L;
}
int main()
{

    cin>>t;
    while(t--)
    {
        cin>>n;
        for(int i=0;i<n;i++)
        scanf("%lf%lf%lf%lf",&s[i].x,&s[i].y,&s[i].vx,&s[i].vy);
          solve();
    }
    return 0;
}

旋轉卡殼+凸包

#include <iostream>
#include <math.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
int ts,n;
typedef struct node
{
    double x,y,vx,vy;

} tt;
tt s[10005],zz[10005];
int top;
int  ss[10005];
double cross(node a,node b,node c)//叉積
{
    return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y);
}

double dis(node a,node b)//距離
{
    return  sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}

bool cmp(node a,node b)
{
    double ans = cross(s[0],a,b);
    if( ans > 0 || (ans == 0 && dis(s[0],a) > dis(s[0],b) )) return true;
    return false;
}

void graham(double t)//凸包模板。。
{
    for(int i=0; i<n; i++)
    {
        s[i].x=(zz[i].x+zz[i].vx*t);
        s[i].y=(zz[i].y+zz[i].vy*t);
    }

    int u=0;
    for(int i = 1; i != n; i ++) //尋找基點
    {
        if(s[u].y > s[i].y || (s[u].y == s[i].y && s[u].x >s[i].x)) u = i;
    }
    if(u)
    {
        swap(s[u].y,s[0].y);
        swap(s[u].x,s[0].x);
    }
    sort(s + 1,s + n,cmp);
    ss[0] = 0;
    ss[1] = 1;
    top = 1;
    for(int i = 2; i != n ; i ++)
    {
        while(top && cross(s[ss[top - 1]],s[ss[top]],s[i] ) < 0) top--;
        ss[++top] = i;
    }
    top ++;
}

double  RC(double t)//旋轉卡殼
{
    graham(t);
    int q,p1,pp,qq,rr,r;
    double ans = 0;
    q = 1;
    ans = dis(s[ss[0]],s[ss[1]]);
    for(int i = 0; i != top ; i ++)
    {
        while(fabs(cross(s[ss[(i+1)%top]],s[ss[i%top]],s[ss[(q+1)%top]])) > fabs(cross(s[ss[(i+1)%top]],s[ss[i%top]],s[ss[q%top]]))) q = (q + 1)%top;
        ans = max(ans, max(dis(s[ss[(i+1)%top]],s[ss[q]]),dis(s[ss[i%top]],s[ss[q]])));
    }
    return ans;
}
void solve()
{
  double L=0.0,R=200000,M;
    double RM=0,LM;
    /*  while(R-L>1e-6)
    {

        M = (L + R) / 2;
        LM = (M + L) / 2;
        RM=LM+0.0001;
        if (RC(LM) < RC(RM)) R = LM;
        else L = LM;
    }

    }*/
    while(R-L>1e-6)
    {
        M=(L+R)/2;
        RM=(M+R)/2;
       if (RC(M) <= RC(RM)) R = RM;
       else L=M;
    }
    printf("%.2lf %.2lf\n",L,RC(L));
    // cout<<LM<<" "<<calc(LM)<<endl;
    // return L;
}
int main()
{

    cin>>ts;
    while(ts--)
    {
        cin>>n;
        for(int i=0; i<n; i++)
            scanf("%lf%lf%lf%lf",&zz[i].x,&zz[i].y,&zz[i].vx,&zz[i].vy);
        solve();
    }
    return 0;
}




發佈了89 篇原創文章 · 獲贊 25 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章