首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 其他相关 >

Codeforces Round #208 (Div. 二)

2013-10-27 
Codeforces Round #208 (Div. 2)A. Dima and Continuous Line链接:http://codeforces.com/contest/358/pro

Codeforces Round #208 (Div. 2)

A. Dima and Continuous Line

链接:http://codeforces.com/contest/358/problem/A

描述:给一个n [1, 10^3], 然后是n个点横坐标xi [-10^6, 10^6],每相邻的两个点是一个半圆直径的两个点。判断这些圆会不会相交。相交输出yes,否则输出no。
思路:数据规模很小,直接暴力15ms水过。

word1<3word2<3 ... wordn<3。然后在得到的字符串上任意位置添加任意个小写字母或数字或大于小于号。现在输入一个字符串text,判断此字符串是否是按照规则构成的。是则输出yes,or no。

思路:先按照规则生成<3word1<3word2<3 ... wordn<3这个字符串。然后进行离散的匹配。只要它的每个字符都在text中出现就yes。

#include <iostream>#include <cstdio>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <deque>#include <string>using namespace std;struct T {int index, val;string ope;T(int index, int val, string s) : index(index), val(val), ope(s) { }};bool cmpind(const T &a, const T &b){return a.index < b.index;}bool cmpval(const T &a, const T &b){return a.val < b.val;}int main(){int n, a;scanf("%d", &n);vector<T> t;int ind = 0;while (n--){scanf("%d", &a);if (a != 0){t.push_back(T(ind++, a, ""));}int k = t.size();if ((a == 0 && !t.empty()) || (a != 0 && n == 0 && !t.empty())){if (k > 3){sort(t.begin(), t.end(), cmpval);vector<T>::iterator it;for (it = t.begin(); it != t.end() - 3; ++it)it->ope = "pushBack";t[k-1].ope= "pushFront", t[k-2].ope = "pushQueue", t[k-3].ope = "pushStack";sort(t.begin(), t.end(), cmpind);for (it = t.begin(); it != t.end(); ++it)cout << it->ope << endl;}else if (k == 3)printf("pushBack\npushQueue\npushStack\n");else if (k == 2)printf("pushBack\npushQueue\n");else if (k == 1)printf("pushBack\n");t.clear();}if (a == 0 && t.empty()){ind = 0;if (k >= 3)printf("3 popFront popQueue popStack\n");else if (k == 2)printf("2 popFront popQueue\n");else if (k == 1)printf("1 popFront\n");elseprintf("0\n");t.clear();}}return 0;}




热点排行