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 + ;
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 ;
}
题意:模拟栈的入栈和出栈操作,并且要求按照 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的更多相关文章
- Codeforces 820B - Mister B and Angle in Polygon
820B - Mister B and Angle in Polygon 思路: 由于正多边形以某个顶点分成的三角形后以这个点为顶点的角都相等,所以可以确定两个点为相邻点,只要再找一个点就够了. 证明 ...
- CodeForces - 820
Mister B and Book ReadingCodeForces - 820A 题意:C,V0,V1,A,L..总共有C页书,第一天以V0速度读,每天加A,但是不能超过V1,并且要从前一天的看到 ...
- Codeforces 821C - Okabe and Boxes
821C - Okabe and Boxes 思路:模拟.因为只需要比较栈顶和当前要删除的值就可以了,所以如果栈顶和当前要删除的值不同时,栈就可以清空了(因为下一次的栈顶不可能出现在前面那些值中). ...
- Codeforces 821C Okabe and Boxes(模拟)
题目大意:给你编号为1-n的箱子,放的顺序不定,有n条add指令将箱子放入栈中,有n条remove指令将箱子移除栈,移出去的顺序是从1-n的,至少需要对箱子重新排序几次. 解题思路:可以通过把栈清空表 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
随机推荐
- Codeforces 1167 E Range Deleting 双指针+思维
题意 给一个数列\(a\),定义\(f(l,r)\)为删除\(a\)中所有满足\(l<=a_i<=r\)的数后的数列,问有多少对\((l,r)\),使\(f(l,r)\)是一个 ...
- bootstrap面板的使用
<div class="panel panel-primary"> <div class="panel-heading"> 头部 < ...
- 7.9T2EASY(easy)
EASY(easy) sol:非常经典的题,取了一次之后,把线段树上这一段变成相反数 然后再贪心取和最大的. 重复以上操作,发现最后一定有对应的解,且根据贪心过程一定 是最大的 线段树上维护区间和最大 ...
- TypeScript----数据类型
TypeScript 简介 TypeScript 由 Microsoft开发和维护的一种开源编程语言.它支持 JavaScript 的所有语法和语义,同时通过作为 ECMAScript 的超集来提供一 ...
- js获取当前页面url信息
<html> <head> <meta charset="utf-8" /> <title></title> <s ...
- Java——重写hashCode()和euqals()方法
1.顺序表的问题 查找和去重效率较低 对于这样的顺序表来说,如果需要查找元素,就需要从第一个元素逐个检查,进行查找.对于需要去重的存储来说,每次存入一个元素之前,就得将列表中的每个元素都比对一遍,效率 ...
- CentOS7 开机启动脚本与命令后台运行
一.& 在 Linux 命令后加上 & 可以在后台运行 二.nohup 对 SIGHUP 信号免疫,对 SIGINT 信号不免疫,可用 shopt | grep hup 查看. 当关 ...
- pandas.DataFrame 中的insert(), pop()
pandas.DataFrame 中的insert(), pop() 在pandas中,del.drop和pop方法都可以用来删除数据,insert可以在指定位置插入数据. 可以看看以下示例. imp ...
- 微信小程序之地址联动
这就是我们要实现的效果 <view class="consignee"> <!-- consignee 收件人 --> <text>收件人: & ...
- ORA-39095: Dump file space has been exhausted
ORA-39095: Dump file space has been exhausted Table of Contents 1. 简述 2. 错误信息 3. 分析 4. 解决 5. 扩展 1 简述 ...