zoukankan      html  css  js  c++  java
  • 省赛训练5-3(四个签到题)

    Floor problem

    In this problem, we have f(n,x)=Floor[n/x]. Here Floor[x] is the biggest integer such that no larger than x. For example, Floor[1.1]=Floor[1.9]=1, Floor[2.0]=2.

    You are given 3 positive integers n, L and R. Print the result of f(n,L)+f(n,L+1)+...+f(n,R), please.

    Input

    The first line of the input contains an integer T (T≤100), indicating the number of test cases.

    Then T cases, for any case, only 3 integers n, L and R (1≤n, L, R≤10,000, L≤R).

    Output

    For each test case, print the result of f(n,L)+f(n,L+1)+...+f(n,R) in a single line.

    Sample Input

    3
    1 2 3
    100 2 100
    100 3 100
    Sample Output
    0
    382
    332
    水题
    #include<cstdio>
    #include<cstring>
    #include<queue>
    #include<stack>
    #include<set>
    #include<map>
    #include<vector>
    #include<iostream>
    #include<algorithm>
    #include<cmath>
    
    const int maxn=1e5+5;
    typedef long long ll;
    using namespace std;
    int a[maxn];
    int main()
    {
        int T;
        cin>>T;
        while(T--)
        {
            int n,L,R;
            scanf("%d%d%d",&n,&L,&R);
            ll sum=0;
            for(int t=L;t<=R;t++)
            {
                sum+=(n/t);
            }
            printf("%lld
    ",sum);
        }
        
        return 0;
    }

    Solve equation

    You are given two positive integers A and B in Base C. For the equation:

    A=k*B+d

    We know there always existing many non-negative pairs (k, d) that satisfy the equation above. Now in this problem, we want to maximize k.

    For example, A="123" and B="100", C=10. So both A and B are in Base 10. Then we have:

    (1) A=0*B+123

    (2) A=1*B+23

    As we want to maximize k, we finally get one solution: (1, 23)

    The range of C is between 2 and 16, and we use 'a', 'b', 'c', 'd', 'e', 'f' to represent 10, 11, 12, 13, 14, 15, respectively.

    Input

    The first line of the input contains an integer T (T≤10), indicating the number of test cases.

    Then T cases, for any case, only 3 positive integers A, B and C (2≤C≤16) in a single line. You can assume that in Base 10, both A and B is less than 2^31.

    Output

    For each test case, output the solution “(k,d)” to the equation in Base 10.

    Sample Input

    3
    2bc 33f 16
    123 100 10
    1 1 2
    Sample Output
    (0,700)
    (1,23)
    (1,0)
    代码:
    #include<cstdio>
    #include<cstring>
    #include<queue>
    #include<stack>
    #include<set>
    #include<map>
    #include<vector>
    #include<iostream>
    #include<algorithm>
    #include<cmath>
    #include<string>
    
    using namespace std;
    char str1[1005],str2[1005];
    
    int power(int x,int y)
    {
        int ans=1;
        for(int t=0;t<y;t++)
        {
            ans=ans*x;
        }
        return ans;
    }
    int main()
    {
        int T;
        cin>>T;
        int s1,s2,s3;
        int ss;
        while(T--)
        {
            s1=0;
            s2=0;
            s3=0;
            cin>>str1>>str2;
            scanf("%d",&ss);
            int len1=strlen(str1);
            int len2=strlen(str2);
            for(int t=len1-1;t>=0;t--)
            {
                if(str1[t]>='0'&&str1[t]<='9')
                s1+=(str1[t]-'0')*power(ss,len1-1-t);
                else
                {
                    s1+=(str1[t]-'a'+10)*power(ss,len1-1-t);
                }
            }
            for(int t=len2-1;t>=0;t--)
            {
                if(str2[t]>='0'&&str2[t]<='9')
                s2+=(str2[t]-'0')*power(ss,len2-1-t);
                else
                {
                    s2+=(str2[t]-'a'+10)*power(ss,len2-1-t);
                }
            }
            int k,d;
            if(s2==0)
            {
                k=s1;
                d=s1;
            }
            else
            {
             k=(s1/s2);
             d=(s1-(k)*s2)%s2;
            }
            printf("(%d,%d)
    ",k,d);
        }
        return 0;
    }

    Star

    Overpower often go to the playground with classmates. They play and chat on the playground. One day, there are a lot of stars in the sky. Suddenly, one of Overpower’s classmates ask him: “How many acute triangles whose inner angles are less than 90 degrees (regarding stars as points) can be found? Assuming all the stars are in the same plane”. Please help him to solve this problem.

    Input

    The first line of the input contains an integer T (T≤10), indicating the number of test cases.

    For each test case:

    The first line contains one integer n (1≤n≤100), the number of stars.

    The next n lines each contains two integers x and y (0≤|x|, |y|≤1,000,000) indicate the points, all the points are distinct

    Output

    For each test case, output an integer indicating the total number of different acute triangles.

    Sample Input

    1
    3
    0 0
    10 0
    5 1000
    Sample Output
    1
    代码:
    #include<cstdio>
    #include<cstring>
    #include<queue>
    #include<stack>
    #include<set>
    #include<map>
    #include<vector>
    #include<iostream>
    #include<algorithm>
    #include<cmath>
    #include<string>
    
    using namespace std;
    struct node
    {
        double x;
        double y;
    }p[105];
    
    int main()
    {
        int T;
        cin>>T;
        while(T--)
        {
            int n;
            scanf("%d",&n);
            for(int t=0;t<n;t++)
            {
                scanf("%lf%lf",&p[t].x,&p[t].y);
            }
            int s=0;
            for(int t=0;t<n;t++)
            {
                for(int j=t+1;j<n;j++)
                {
                    for(int k=j+1;k<n;k++)
                    {
                        double a=(p[t].x-p[j].x)*(p[t].x-p[j].x)+(p[t].y-p[j].y)*(p[t].y-p[j].y);
                        double b=(p[t].x-p[k].x)*(p[t].x-p[k].x)+(p[t].y-p[k].y)*(p[t].y-p[k].y);
                        double c=(p[j].x-p[k].x)*(p[j].x-p[k].x)+(p[j].y-p[k].y)*(p[j].y-p[k].y);
                        
                        if(a>=b&&a>=c)
                        {
                           if(b+c-a>0)
                           {
                               s++;
                           }
                        }
                        else if(b>=a&&b>=c)
                        {
                           if(a+c-b>0)
                           {
                               s++;
                           }
                        }
                        else if(c>=a&&c>=b)
                        {
                            if(a+b-c>0)
                           {
                               s++;
                           }
                        }
                        
                    }
                }
            }
            printf("%d
    ",s);
            
        }
        return 0;
    }

    Min Number

    Now you are given one non-negative integer n in 10-base notation, it will only contain digits ('0'-'9'). You are allowed to choose 2 integers i and j, such that: i!=j, 1≤i<j≤|n|, here |n| means the length of n’s 10-base notation. Then we can swap n[i] and n[j].

    For example, n=9012, we choose i=1, j=3, then we swap n[1] and n[3], then we get 1092, which is smaller than the original n.

    Now you are allowed to operate at most M times, so what is the smallest number you can get after the operation(s)?

    Please note that in this problem, leading zero is not allowed!

    Input

    The first line of the input contains an integer T (T≤100), indicating the number of test cases.

    Then T cases, for any case, only 2 integers n and M (0≤n<10^1000, 0≤M≤100) in a single line.

    Output

    For each test case, output the minimum number we can get after no more than M operations.

    Sample Input

    3
    9012 0
    9012 1
    9012 2

    Sample Output
    9012
    1092
    1029
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #include<queue>
    #include<stack>
    #include<set>
    #include<map>
    #include<vector>
    #include<cmath>
    
    using namespace std;
    const int maxn=1e5+5;
    typedef long long ll;
    char  str[maxn];
    char a[maxn];
    int main()
    {
        int T;
        cin>>T;
        int m;
        int len;
        while(T--)
        {
           scanf("%s%d",str,&m);    
           len=strlen(str);
           int s=0;
           for(int t=0;t<len;t++)
           {
                  if(s==m)
                  {
                      break;
                  }
                  char minn=str[t];
                  int k=t;
                  for(int j=t;j<len;j++)
                  {
                      if(t==0)
                      {
                          if(minn>str[j]&&str[j]!='0')
                          {
                              minn=str[j];
                              k=j;
                          }
                      }
                      else
                      {
                          if(minn>str[j])
                          {
                              minn=str[j];
                              k=j;
                          }
                      }
                  }
                  if(k!=t)
                  {
                      swap(str[t],str[k]);
                      s++;
                  }
           }
           printf("%s
    ",str);
        }
        return 0;
    }
  • 相关阅读:
    Linux系统根目录各文件夹的含义
    openstack与VMware workStation的区别
    VMWare的网络
    VMware Workstation 的安装和使用
    Jmeter简介
    加快建设创新型国家
    c语言指针详解
    [翻译]NUnit--前言(一)
    [翻译]NUnit--Getting Started(二)
    [测试]单元测试框架NUnit
  • 原文地址:https://www.cnblogs.com/Staceyacm/p/10804724.html
Copyright © 2011-2022 走看看