本文主要是介绍Codeforces Round #281 (Div. 2)A(构造+暴力模拟),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目链接:http://codeforces.com/problemset/problem/493/A
解题思路:
暴力的判断,分三种情况去判断即可。注意如果之前已经被罚下场后,那么在后面的罚下情况不应该算在输出结果内。
完整代码:
#include <algorithm>
#include <iostream>
#include <cstring>
#include <complex>
#include <cstdio>
#include <string>
#include <cmath>
using namespace std;
typedef long long LL;
const int MOD = int(1e9)+7;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1.0); //M_PI;
string a , b;
const int maxn = 1001;
struct node
{string name;int num , time;
}k[maxn];struct node2
{int time;string name;int num;string stau;
}t[maxn];int main()
{#ifdef DoubleQfreopen("in.txt","r",stdin);#endifstd::ios::sync_with_stdio(false);std::cin.tie(0);while(cin >> a >> b){int n;cin >> n;int cnt = 0;for(int i = 0 ; i < n ; i ++){cin >> t[i].time >> t[i].name >> t[i].num >> t[i].stau;int flag = 0;for(int j = 0 ; j < i ; j ++){if(t[j].name == t[i].name && t[i].num == t[j].num && t[j].stau == "r"){flag = 1;break;}if(t[j].num == t[i].num && t[j].name == t[i].name && t[j].stau == "y" && t[i].stau == "y"){if(t[i].name == "a")k[cnt].name = b;elsek[cnt].name = a;k[cnt].num = t[i].num;k[cnt++].time = t[i].time;t[j].stau = "r";t[i].stau = "r";flag = 1;break;}}if(flag == 1)continue;if(t[i].stau == "r" && t[i].name == "h"){k[cnt].name = a;k[cnt].num = t[i].num;k[cnt++].time = t[i].time;}else if(t[i].stau == "r" && t[i].name == "a"){k[cnt].name = b;k[cnt].num = t[i].num;k[cnt++].time = t[i].time;}}for(int i = 0 ; i < cnt ; i ++)cout << k[i].name << " " << k[i].num << " " << k[i].time << endl;}
}
这篇关于Codeforces Round #281 (Div. 2)A(构造+暴力模拟)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!