zoukankan      html  css  js  c++  java
  • CodeForces 820B + 821C

    (点击题目即可查看原题)

    820B Mister B and Angle in Polygon 

    题意:在一个正n边形中,每个顶点按顺序记为1~n,正n边形中任意三点顶点组成一个角,∠x1x2x3,问正n边形中这样组成的角 ∠x1x2x3 最接近角度 x 的组合,并输出x1,x2,x3。

    思路:通过画出正五边形和正边形,发现最大的角度为 (n - 2)*Pi / n,随后次大值为 (n-2)*Pi / n - Pi/n ,第三大值为 (n - 2)*Pi /n - 2 * Pi / n,...,最小为 Pi / n ,而且我们固定相邻的两点,按顺序枚举第三个点,我们获得所有的角度,所以我们枚举第三个点,找到最接近x的组合,记录并输出即可

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<queue>
    #include<string>
    #include<fstream>
    #include<vector>
    #include<stack>
    #include <map>
    #include <iomanip>
    
    #define bug cout << "**********" << endl
    #define show(x, y) cout<<"["<<x<<","<<y<<"] "
    #define LOCAL = 1;
    using namespace std;
    typedef long long ll;
    const int inf = 0x3f3f3f3f;
    const ll mod = 1e9 + 7;
    const int Max = 1e5 + 10;
    
    int n, a;
    
    int main()
    {
    #ifdef LOCAL
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif
        while (scanf("%d%d", &n, &a) != EOF)
        {
            int id = 3;
            double now = (1.0 * n - 2) * 180.0 / n;         //当前角度
            double dis = abs(now-a);                     //差值
            for (int i = 4; i <= n; i++)
            {
                now -= 180.0 / n;
                if (dis > abs(now - a))
                {
                    id = i;
                    dis = abs(now-a);
                }
            }
            printf("1 2 %d
    ",id);
        }
        return 0;
    }
    View Code

    821C Okabe and Boxes 

    题意:模拟栈的入栈和出栈操作,并且要求按照 1 ~n 的顺序将数出栈,如果栈顶不为当前需要的出栈数字,这样就不正确,但是我们可以对栈中元素重新排序,使得最终我们可以将栈中元素按顺序出栈,数据保证当前需要出栈的数一定存在于栈中。

    思路:(看一眼数据范围,就决定放弃老老实实地模拟入栈和出栈),注意到数据保证当前需要出栈的数一定存在于栈中,那么我们对栈中的数重新排序后,原来栈中的数一定是降序排列的(不一定连续,但要求输出的数肯定会按顺序将排序后的元素出栈),那么我们每一次排序后,将栈中元素清空,如果某一次出栈操作时栈为空,那就说明此次出栈的是之前已经排好序了的数,这样就按要求输出当前需要的数了,而如果当前栈不为空,且栈顶元素不是当前需要出栈的元素,那么我们执行“排序”操作——将栈清空。按这样操作这样就可以得到答案了。

     

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<queue>
    #include<string>
    #include<fstream>
    #include<vector>
    #include<stack>
    #include <map>
    #include <iomanip>
    
    #define bug cout << "**********" << endl
    #define show(x, y) cout<<"["<<x<<","<<y<<"] "
    #define LOCAL = 1;
    using namespace std;
    typedef long long ll;
    const int inf = 0x3f3f3f3f;
    const ll mod = 1e9 + 7;
    const int Max = 3e5 + 10;
    
    int n,  x;
    char order[10];
    int s[Max],top;
    
    int main()
    {
    #ifdef LOCAL
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif
        while(scanf("%d",&n)!=EOF)
        {
            int sum = 0;
            n *= 2;
            int now = 1;
            top = 0;
            while (n--)
            {
                scanf("%s",order);
                if(order[0] == 'a')
                {
                    scanf("%d",&x);
                    s[++top] = x;
                }
                else
                {
                    if(top == 0)
                    {
                        now++;
                    }
                    else if(s[top] == now)
                    {
                        now++;top--;
                    }
                    else
                    {
                        now++;top = 0 ;sum++;
                    }
                }
            }
            printf("%d
    ",sum);
        }
        return 0;
    }
    View Code

     

  • 相关阅读:
    jquery 的ready() 与window.onload()的区别
    使IE6同样支持圆角效果
    菜鸟级三层框架(EF+MVC)项目实战之 系列一 EF零基础创建领域模型
    asp.net webform 与mvc 共享session
    用户密码安全存储解决方案
    vs2010 web负载测试解决提示:结果存储类型为“Database”,但尚未指定结果储存库连接字符串。
    菜鸟级三层框架(EF+MVC)项目实战之 系列二 对数据访问层的抽象中
    菜鸟级三层框架(EF+MVC)项目实战之 系列四 UI层ASP.NET MVC实现CRUD
    菜鸟级三层框架(EF+MVC)项目实战之 系列二 对数据访问层的抽象下
    WP7之文件传送利器(web service)
  • 原文地址:https://www.cnblogs.com/winter-bamboo/p/11360706.html
Copyright © 2011-2022 走看看