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

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. Windows上redis下载与安装

    一.redis是什么 非关系型内存数据库,以key-value的形式将数据储存在内存中.Mysql是关系型数据库,数据是保存在硬盘中 二.redis下载安装 1.要安装Redis,首先要获取安装包. ...

  2. Mysql主从同步 异常Slave_SQL_Running: No

    在刚搭建好的mysql主从节点上对从节点进行操作,导致同步异常:报错如下: 从节点执行: mysql> show slave status\G;************************* ...

  3. P1200 [USACO1.1]你的飞碟在这儿Your Ride Is Here

    输入格式: 第1行:一个长度为111到666的大写字母串,表示彗星的名字. 第2行:一个长度为111到666的大写字母串,表示队伍的名字. 输出格式: 如果能搭配,就输出“GO”,否则输出“STAY” ...

  4. Vue_(组件通讯)动态组件结合keep-alive

    keep-alive 传送门 <keep-alive> 包裹动态组件时,会缓存不活动的组件实例,而不是销毁它们.和 <transition> 相似,<keep-alive ...

  5. Vue_(组件)实例属性

    Vue实例属性与方法中文文档 传送门   Vue实例属性:vue实例直接调用的属性 Learn 一.vm.$data:获取属性 二.vm.$el:获取实例挂载的元素 三.vm.$options:获取自 ...

  6. VirtualBox更改虚拟硬盘 VDI文件空间大小的方法

    cmd执行 C:\Oracle\VirtualBox\VBoxManage.exe modifyhd

  7. Java-内存模型(JSR-133)

    Java 内存模型(Java Memory Model,JMM)看上去和 Java 内存结构(JVM 运行时内存结构)差不多,但这两者并不是一回事.JMM 并不像 JVM 内存结构一样是真实存在的,它 ...

  8. C#类型转换类(通用类)

    //     /// 类型转换类     /// 处理数据库获取字段为空的情况     ///     public static class DBConvert     {         #reg ...

  9. javascript 生成img标签的3种方式(对象、方法、html)

    <div id="d1"></div> <script> //HTML function a(){ document.getElementByI ...

  10. Python 正则表达式【二】

    关于前向,后向,匹配,非匹配 Matches if ... matches next, but doesn’t consume any of the string. This is called a ...