• 可怕最可爱


    上次比赛和电子科大同步赛抢了J题一个一血,差点蹦起来,结果发现TMD交成自己的号了。。。那个号在我们队的号之下就是一个僵尸号!哼唧哼唧!

    好,第一个题,我数论没学好,知道三角形三个坐标怎么算面积,这个公式我一定要记住:1/2|x1y2+x2y3+x3y1-x1y3-x2y1-x3y2|

    这个题题意也蛮简单的,就是给你一个凸多边形,找三个点组成的三角形面积最小,那当然是比较相邻的三个点啦。

    You are given a strictly convex polygon. Find the minimal possible area of non-degenerate triangle whose vertices are the vertices of the polygon.

    Input

    The first line contains a single integer n (3 ≤ n ≤ 200000) — the number of polygon vertices.

    Each of the next n lines contains two integers xi and yi ( - 109 ≤ xi, yi ≤ 109) — the coordinates of polygon vertices.

    The polygon is guaranteed to be strictly convex. Vertices are given in the counterclockwise order.

    Output

    It is known that the area of triangle whose vertices are the integer points on the grid is either integer or half-integer.

    Output a single integer — the required area, multiplied by 2.

    Examples

    Input
    4
    0 1
    3 0
    3 3
    -1 3
    Output
    5
    Input
    3
    0 0
    1 0
    0 1
    Output
    1
    Input
    4
    -999999991 999999992
    -999999993 -999999994
    999999995 -999999996
    999999997 999999998
    Output
    3999999948000000156
    #include <cstdio>
    #include <iostream>
    #include <string>
    #include <algorithm>
    #include <cstring>
    #include <cmath>
    using namespace std;
    struct node{
        long long x,y;
    }s[200005];
     unsigned long long area(node a,node b,node c){
        unsigned long long sum=abs(a.x*b.y+b.x*c.y+c.x*a.y-a.x*c.y-b.x*a.y-c.x*b.y);
        return sum;
     }
    int main()
    {
        int n,m;
        cin>>n;
        for(int i=0;i<n;i++) cin>>s[i].x>>s[i].y;
        unsigned long long minx=1e19;
        for(int i=0;i<n-2;i++) minx=min(minx,area(s[i],s[i+1],s[i+2]));
        minx=min(minx,area(s[0],s[n-1],s[n-2]));
        minx=min(minx,area(s[0],s[1],s[n-1]));
        cout<<minx<<endl;
    }

    这道题当时我和pzr都没读懂这道题要干嘛,而且样例输出也比较奇怪,在我读了很多很多很多遍之后,我终于读懂了!

    二分最终的答案:因为最大需要说服的人的个数就是m ,所以我们每次二分下去,当去检验某个答案时:从头开始遍历,如果说服的名额还充足,就将这个人说服,因为现在说服会增加评论量,对以后会产生贡献,所以结果不会变坏;当满足m个人时,那么将上界缩小,再次二分下去,同理对于下界放大的情况。

    二分查找这类题见得挺少的,这道题挺典型的。

    The studio «Lodka Gaming» is engaged in advertising of their new game «.C.O.N.T.E.S.T: Unexpected Behaviour». The studio's marketer is planning to communicate with n videobloggers one by one (in the predetermined order, starting from the 1-st and ending with the n-th), offering them to record a video review on the game. All people are different and videobloggers are as well, therefore the i-th videoblogger will record a review in two cases: either he is interested in this game, or there are already at least ai video reviews on this game.

    The studio wants to have at least m video reviews in the Internet. The game designer of «Lodka Gaming» understands these video reviews possibly would not appear by themselves, so he wants to convince some video bloggers that they are actually interested in this game. Which minimal number of videobloggers are needed to beconvinced?

    Input

    The first line contains two integers n and m (1 ≤ n ≤ 200000, 1 ≤ m ≤ n) — the number of videobloggers and the required number of video reviews.

    The second line contains n integers ai (0 ≤ ai ≤ 200000) — the minimal number of video reviews that should appear in the Internet so that the i-th videoblogger will record a review in case he is not interested in the game.

    Output

    Output a single integer — the minimal number of videobloggers who have to beconvinced to record a video review on the game in order to achieve at least m total video reviews in the Internet.

    #include<iostream>
    #include<string.h>
    #include<math.h>
    #include<algorithm>
    using namespace std;
    int a[200000];
    int n, m;
    bool judg(int x)
    {
        int  res = 0;
        for (int i = 1; i <= n; i++)
        {
            if (a[i] <= res)
                res++;
            else if (x)
            {
                res++;
                x--;
            }
            if (res == m)
            return 1;
        }
        return 0;
    }
    int main()
    {
        cin >> n >> m;
        int i, j;
        for (i = 1; i <= n; i++)
            cin >> a[i];
        int l = 0, r = m;
        int res = m;
        while (l<=r)
        {
            int mid =(l+r)/2;
            if (judg(mid))
            {
                r=mid-1;
                res=mid;
            }
            else
                l=mid+1;
        }
        cout << res << endl;
    }

    这道题我觉得挺有趣的,最开始做的时候连门都没摸到,看了题解豁然开朗,原来是纯数学问题。

    当面积相等的时候,用基本不等式我们可以得出正方形的周长最小,那么我们可以把它转换成一个图形问题。

    我们可以考虑找到一个x和一个y使得x*y>=n并且x+y尽可能的小,然后我们就将n个数分成x组,并且每组有y个数,这y个数是按顺序排列的,但是要满足前一组的权值大于后一组。

    每到根号n就翻转一次,得出来的答案最小。

    C. The Phone Number
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Mrs. Smith is trying to contact her husband, John Smith, but she forgot the secret phone number!

    The only thing Mrs. Smith remembered was that any permutation of nn can be a secret phone number. Only those permutations that minimize secret value might be the phone of her husband.

    The sequence of nn integers is called a permutation if it contains all integers from 11 to nn exactly once.

    The secret value of a phone number is defined as the sum of the length of the longest increasing subsequence (LIS) and length of the longest decreasing subsequence (LDS).

    A subsequence ai1,ai2,,aikai1,ai2,…,aik where 1i1<i2<<ikn1≤i1<i2<…<ik≤n is called increasing if ai1<ai2<ai3<<aikai1<ai2<ai3<…<aik. If ai1>ai2>ai3>>aikai1>ai2>ai3>…>aik, a subsequence is called decreasing. An increasing/decreasing subsequence is called longest if it has maximum length among all increasing/decreasing subsequences.

    For example, if there is a permutation [6,4,1,7,2,3,5][6,4,1,7,2,3,5], LIS of this permutation will be [1,2,3,5][1,2,3,5], so the length of LIS is equal to 44.LDS can be [6,4,1][6,4,1], [6,4,2][6,4,2], or [6,4,3][6,4,3], so the length of LDS is 33.

    Note, the lengths of LIS and LDS can be different.

    So please help Mrs. Smith to find a permutation that gives a minimum sum of lengths of LIS and LDS.

    Input

    The only line contains one integer nn (1n1051≤n≤105) — the length of permutation that you need to build.

    Output

    Print a permutation that gives a minimum sum of lengths of LIS and LDS.

    If there are multiple answers, print any.

    Examples
    input
    Copy
    4
    output
    Copy
    3 4 1 2
    input
    Copy
    2
    output
    Copy
    2 1
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int maxn = 1e5+77;
    #define INF 0x3f3f3f3f
    stack<int> st;
    int main(){
        ll n;
        cin>>n;
        int d=sqrt(n);
        for(int i=1;i<=n;i++)
        {
            st.push(i);
            if(i%d==0)
            {
                while(!st.empty())
                {
                    cout<<st.top()<<" ";
                    st.pop();
                }
            }
        }
            while(!st.empty())
            {
                cout<<st.top()<<" ";
                st.pop();
            }
        cout<<endl;
        return 0;
    } 


  • 相关阅读:
    170322操作系统定义、功能、位置与历史
    java 多线程
    java 网络编程TCP程序设计
    java 事件处理机制
    java GUI编程
    170321php3第4章 PHP5的基本语法+作业九九乘法表
    170320网络编程 udpclient udpGroupClient
    二叉树线索化
    哈希表
    二叉搜索树
  • 原文地址:https://www.cnblogs.com/kepa/p/9465162.html
Copyright © 2020-2023  润新知