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

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. PCI-CAN卡驱动与数据通信调试小记

    以前做项目,不注意记录调试过程中遇到的问题,以后应该注意这一点.今天抽空总结一下PCI-CAN卡驱动与数据通信调试过程中遇到的问题,方便以后回忆和思考. 1. 中断服务之字节流报文组包状态机 这是一个 ...

  2. vue-property-decorator知识梳理

    仓库地址: /* npm 仓库地址 */ // https://www.npmjs.com/package/vue-property-decorator /* github地址 */ // https ...

  3. BZOJ刷题列表【转载于hzwer】

    沿着黄学长的步伐~~ 红色为已刷,黑色为未刷,看我多久能搞完吧... Update on 7.26 :之前咕了好久...(足见博主的flag是多么emmm......)这几天开始会抽时间刷的,每天几道 ...

  4. Java EE 之 Hibernate异常解决:org.hibernate.exception.SQLGrammarException: could not execute statement

    本质原因:配置的Java Bean,由Hibernate自动产生的SQL语句中有语法错误 原因如下: 情况1.存在字段名/表名与数据库关键字冲突 情况2.MySQL5.0以后与MySQL5.0以前事务 ...

  5. 11.二进制中1的个数 Java

    题目描述 输入一个整数,输出该数二进制表示中1的个数.其中负数用补码表示. 思路 当n不等于0时执行以下循环: 1.判断n的最低位是否为1,若为1,则计数器加1 2.将n无符号右移1位(若使用带符号移 ...

  6. C++入门经典-例8.8-虚继承

    1:以前讲到从CBird类和CFish类派生子类CWaterBird时,在CWaterBird类中将存在两个CAnimal类的复制.那么如何在派生CWaterBird类时使其只存在一个CAnimal基 ...

  7. Cannot use unsafe construct in safe context

    https://stackoverflow.com/questions/25953887/how-to-use-unsafe-code-in-safe-contex I am not sure if ...

  8. Php+Redis函数使用总结

    因项目需求,冷落了redis,今天再重新熟悉一下: <?php //连接 $redis = New Redis(); $redis->connect('127.0.0.1','6379', ...

  9. javascript定时器方法使用

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. SSH2配置

    Ubuntu14.04配置openSSH-server时报错,很有可能是因为如下的报错原因 这个问题大概应该是你的/etc/apt/的源有问题,但大概可以这么解决:1.sudo apt-get pur ...