• 啦啦啦


    这道题是找可以组成矩形的四根木棍,使组成的满足那个公式最小,用memset可能会超时,化简公式之后,要让x=y最小,那我们就要尽可能的接近

    C. Minimum Value Rectangle
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    You have nn sticks of the given lengths.

    Your task is to choose exactly four of them in such a way that they can form a rectangle. No sticks can be cut to pieces, each side of the rectangle must be formed by a single stick. No stick can be chosen multiple times. It is guaranteed that it is always possible to choose such sticks.

    Let SS be the area of the rectangle and PP be the perimeter of the rectangle.

    The chosen rectangle should have the value P2SP2S minimal possible. The value is taken without any rounding.

    If there are multiple answers, print any of them.

    Each testcase contains several lists of sticks, for each of them you are required to solve the problem separately.

    Input

    The first line contains a single integer TT (T1T≥1) — the number of lists of sticks in the testcase.

    Then 2T2T lines follow — lines (2i1)(2i−1) and 2i2i of them describe the ii-th list. The first line of the pair contains a single integer nn (4n1064≤n≤106) — the number of sticks in the ii-th list. The second line of the pair contains nn integers a1,a2,,ana1,a2,…,an (1aj1041≤aj≤104) — lengths of the sticks in the ii-th list.

    It is guaranteed that for each list there exists a way to choose four sticks so that they form a rectangle.

    The total number of sticks in all TT lists doesn't exceed 106106 in each testcase.

    Output

    Print TT lines. The ii-th line should contain the answer to the ii-th list of the input. That is the lengths of the four sticks you choose from theii-th list, so that they form a rectangle and the value P2SP2S of this rectangle is minimal possible. You can print these four lengths in arbitrary order.

    If there are multiple answers, print any of them.

    Example
    input
    Copy
    3
    4
    7 2 2 7
    8
    2 8 1 4 8 2 1 5
    5
    5 5 5 5 5
    output
    Copy
    2 7 7 2
    2 2 1 1
    5 5 5 5
    #include <iostream>
    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    #include<algorithm>
    #define inf 0x3f3f3f3f
    using namespace std;
    int a[1000001],j,b[1000001];
    int main()
    {
        int t,n,i,m,x,y;
        cin>>t;
        while(t--)
        {
            for(i=0; i<10001; i++)
                a[i]=0;
            int p=0;
            scanf("%d",&n);
            for(i=0; i<n; i++)
            {
               scanf("%d",&m);
                a[m]++;
                if(a[m]==2||a[m]==4)
                {
                    b[p++]=m;
                }
            }
            sort(b,b+p);
            double minn=inf;
            for(i=0;i<p-1;i++)
            {
                if(b[i]==b[i+1])
                {
                    x=b[i];
                    y=b[i+1];
                    break;
                }
                double temp=(double)b[i+1]/b[i];
                if(temp<minn)
                {
                    minn=temp;
                    x=b[i];
                    y=b[i+1];
                }
            }return 0;
    
    }

    这道题就是找规律我们可以得到答案2k+1n(2k1),但是为了避免超时,要使用快乘和快速幂解决,还有要注意的一点是取模之后公式前面可能比后面小,所以我们要加上mod再取余一次,不然就是负的

    C. Nastya and a Wardrobe
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month).

    Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with the 50% probability. It happens every month except the last one in the year.

    Nastya owns x dresses now, so she became interested in the expected number of dresses she will have in one year. Nastya lives in Byteland, so the year lasts for k + 1 months.

    Nastya is really busy, so she wants you to solve this problem. You are the programmer, after all. Also, you should find the answer modulo 109 + 7, because it is easy to see that it is always integer.

    Input

    The only line contains two integers x and k (0 ≤ x, k ≤ 1018), where x is the initial number of dresses and k + 1 is the number of months in a year in Byteland.

    Output

    In the only line print a single integer — the expected number of dresses Nastya will own one year later modulo 109 + 7.

    Examples
    input
    Copy
    2 0
    output
    Copy
    4
    input
    Copy
    2 1
    output
    Copy
    7
    input
    Copy
    3 2
    output
    Copy
    21
    #include <iostream>
    #include<string.h>
    #include<math.h>
    #include<algorithm>
    #include<cstdio>
    using namespace std;
    const int mod=1e9+7;
    long long quickmul(long long a,long long b)
    {
        long long ans=0;
        while(b)
        {
        if(b&1)
        {
            ans=(ans+a)%mod;
        }
        a=(a+a)%mod;
        b>>=1;
        }
        return  ans;
    }
    long long quickpow(long long a,long long b)
    {
        long long ans=1;
        while(b)
        {
            if(b&1)
            {
                ans=(ans*a)%mod;
            }
            a=(a*a)%mod;
            b>>=1;
        }
        return ans;
    }
    int main()
    {
      long long n,k;
      cin>>n>>k;
      if(n==0)
      {
          cout<<0<<endl;
          return 0;
      }
      long long res=(quickmul(quickpow(2, k + 1), n) % mod) - (quickpow(2, k) - 1 + mod) % mod;
      res=(res+mod)%mod;
      cout<<res<<endl;
      return 0;
    }

    还有一道是那天打比赛的题,一定要记住多边形内角和公式:(n-2)*180,然后计算出多边形面积,减去圆的面积,每层叠加就行了。

    #include <iostream>
    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    #include<algorithm>
    #include<stdlib.h>
    #define pi acos(-1.0)
    using namespace std;
    int main()
    {
        freopen("glorious.in","r",stdin);
        int t,n,k,cnt=0;
        double r;
        scanf("%d",&t);
        while(t--)
        {
            cnt++;
            scanf("%d%lf%d",&n,&r,&k);
             double sum=0;
            while(n--)
            {
                double r2=(double)r/(sin(pi*(k-2)/k/2));
                double kepa=2.0*sqrt(r2*r2-(double)r*r);
                sum+=(double)k/2.0*kepa*r-pi*r*r;
              
  • 相关阅读:
    【转】Java操作CSV文件导入导出
    【转】Java压缩和解压文件工具类ZipUtil
    Python之multiprocessing.Pool(创建多个子进程)
    Openstack平台虚拟机疏散失败提示(pymysql.err.OperationalError) (2013, 'Lost connection to MySQL server during query')问题
    kubernetes部署redis主从高可用集群
    Ceph性能测试
    python日志模块
    kubernetes删除pod,pod一直处于Terminating状态
    python执行提示“ImportError: No module named OpenSSL.crypto”
    二进制部署kubernetes集群_kube-apiserver提示"watch chan error: etcdserver: mvcc: required revision has been compacted'
  • 原文地址:https://www.cnblogs.com/kepa/p/9504709.html
Copyright © 2020-2023  润新知