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

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 + ;
const int Max = 1e5 + ; 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 = ;
double now = (1.0 * n - ) * 180.0 / n; //当前角度
double dis = abs(now-a); //差值
for (int i = ; i <= n; i++)
{
now -= 180.0 / n;
if (dis > abs(now - a))
{
id = i;
dis = abs(now-a);
}
}
printf("1 2 %d\n",id);
}
return ;
}

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 + ;
const int Max = 3e5 + ; int n, x;
char order[];
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 = ;
n *= ;
int now = ;
top = ;
while (n--)
{
scanf("%s",order);
if(order[] == 'a')
{
scanf("%d",&x);
s[++top] = x;
}
else
{
if(top == )
{
now++;
}
else if(s[top] == now)
{
now++;top--;
}
else
{
now++;top = ;sum++;
}
}
}
printf("%d\n",sum);
}
return ;
}

CodeForces 820B + 821C的更多相关文章

  1. Codeforces 820B - Mister B and Angle in Polygon

    820B - Mister B and Angle in Polygon 思路: 由于正多边形以某个顶点分成的三角形后以这个点为顶点的角都相等,所以可以确定两个点为相邻点,只要再找一个点就够了. 证明 ...

  2. CodeForces - 820

    Mister B and Book ReadingCodeForces - 820A 题意:C,V0,V1,A,L..总共有C页书,第一天以V0速度读,每天加A,但是不能超过V1,并且要从前一天的看到 ...

  3. Codeforces 821C - Okabe and Boxes

    821C - Okabe and Boxes 思路:模拟.因为只需要比较栈顶和当前要删除的值就可以了,所以如果栈顶和当前要删除的值不同时,栈就可以清空了(因为下一次的栈顶不可能出现在前面那些值中). ...

  4. Codeforces 821C Okabe and Boxes(模拟)

    题目大意:给你编号为1-n的箱子,放的顺序不定,有n条add指令将箱子放入栈中,有n条remove指令将箱子移除栈,移出去的顺序是从1-n的,至少需要对箱子重新排序几次. 解题思路:可以通过把栈清空表 ...

  5. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  6. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  7. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  8. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  9. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

随机推荐

  1. Luogu P5564 [Celeste-B]Say Goodbye (多项式、FFT、Burnside引理、组合计数)

    题目链接 https://www.luogu.org/problem/P5564 题解 这题最重要的一步是读明白题. 为了方便起见下面设环长可以是\(1\), 最后统计答案时去掉即可. 实际上就相当于 ...

  2. 记一次关于springboot的netty版本冲突问题

    冲突的地放其实很多,大概都是类似,找不到哪个方法了: 类似于: Error starting ApplicationContext. To display the conditions report ...

  3. JavaWeb-SpringSecurity自定义登陆页面

    系列博文 项目已上传至guthub 传送门 JavaWeb-SpringSecurity初认识 传送门 JavaWeb-SpringSecurity在数据库中查询登陆用户 传送门 JavaWeb-Sp ...

  4. mysql基础知识语法汇总整理(一)

    mysql基础知识语法汇总整理(二)   连接数据库操作 /*连接mysql*/ mysql -h 地址 -P 端口 -u 用户名 -p 密码 例如: mysql -u root -p **** /* ...

  5. leetcode题目11.盛最多水的容器(中等)

    题目描述: 给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0).找出其 ...

  6. 浏览器缓存及vw和vh的使用

    在浏览器缓存中不仅有 cookie 还有了别的选择 Storage 浏览器又分了两种缓存:sessionStorage localStorage localStorage 缓存:是一种永久的缓存,也就 ...

  7. Git常用操作详细说明

    1.1  git的安装,没有什么特殊的,直接下一步就OK了: 1.2  搜索找到Git,会出现两个git,一个是Bash(命令行),一个GUI(页面),一般用 Bash,GUI页面比较老: 1.3  ...

  8. Throwable 源码阅读

    Throwable 属性说明 /** * Java 语言中所有错误和异常的基类,此类及其子类才能通过 throws 被 JVM 虚拟机抛出. * @since 1.0 */ public class ...

  9. OGG-01877 Missing explicit accessrule for server collector

    OGG-01877 Missing explicit accessrule for server collector Table of Contents 1. OGG-01877 1 OGG-0187 ...

  10. 工具类 分页工具类PageParamBean

    自己编写的分页工具类,根据不同的数据库类型,生成对应的分页sql信息,分享给大家,希望大家共勉,工具类有些地方,大家可能不需要,请根绝自己的需要进行修改使用,核心逻辑都在,如果大家觉得有什么不妥,欢迎 ...