A.模拟题
题目链接:http://codeforces.com/contest/493/problem/A
题意为:给出两个队伍名home队和away队,然后给出n条信息,每条信息包括四个值,在什么时间,哪个队,该队的几号,得到了黄牌或者红牌,如果得到了两个黄牌,那么自动得到一张红牌,我们关心的是两个队的球员第一次得到红牌的情况,如果在输入的时候发现有球员第一次得到了红牌,那么就输出该球员的队伍名,是几号,在什么时候得到了一张红牌。
得到一张黄牌用1表示,一张红牌用2表示,用两个map<int,int>存放两个球队每个球员的犯规情况,如果是2就说明已经得到了一张红牌。
代码:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <cmath>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cctype>
using namespace std;
#define ll long long
string home,away;
map<int,int>h;
map<int,int>a;
int main()
{
cin>>home>>away;
int n;
cin>>n;
int time,no;
char tap,color;
while(n--)
{
cin>>time>>tap>>no>>color;
if(tap=='a')
{
if(a[no]==2)
continue;
else
{
if(color=='r')
{
a[no]=2;
cout<<away<<" "<<no<<" "<<time<<endl;
}
else
{
a[no]++;
if(a[no]==2)
cout<<away<<" "<<no<<" "<<time<<endl;
}
}
}
else
{
if(h[no]==2)
continue;
else
{
if(color=='r')
{
h[no]=2;
cout<<home<<" "<<no<<" "<<time<<endl;
}
else
{
h[no]++;
if(h[no]==2)
cout<<home<<" "<<no<<" "<<time<<endl;
}
}
}
}
return 0;
}
B.模拟题
题目链接:http://codeforces.com/contest/493/problem/B
题意为:依次给出n个分数,或者大于0,或者小于0,如果大于0代表a的得分,如果小于0,其绝对值代表b的得分,最后谁的总分高,谁就赢,如果总分相同,那么分数序列中字典序高的人赢,比如a 的分数序列为 15 20 22 而b 的分数序列为 15 24 22,则b的字典序高,因为 15=15,20<24,如果二者的字典序也一样,分数序列相同,那么输入过程中最后一次的输入是谁的分数,谁就赢。
分情况,if,else
代码:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <cmath>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cctype>
using namespace std;
#define ll long long
const int maxn=200010;
ll a[maxn];
ll b[maxn];
ll suma=0;
ll sumb=0;
int n;
ll score;
int last;
int main()
{
cin>>n;
int lena=0;
int lenb=0;
for(int i=1;i<=n;i++)
{
cin>>score;
if(score>0)
{
a[++lena]=score;
suma+=score;
}
else
{
b[++lenb]=-score;
sumb+=(-score);
}
if(i==n)//记录最后一次是谁的得分
{
if(score>0)
last=1;
else
last=2;
}
}
if(suma>sumb)//存在一方比另一方分高的情况
cout<<"first"<<endl;
else if(sumb>suma)
cout<<"second"<<endl;
else//分数相同
{
int flag=0;
int len=min(lena,lenb);
for(int i=1;i<=len;i++)
{
if(a[i]>b[i])//判断谁的字典序大
{
flag=1;
break;
}
if(b[i]>a[i])
{
flag=2;
break;
}
}
if(flag==1)
{
cout<<"first"<<endl;
}
else if(flag==2)
{
cout<<"second"<<endl;
}
else //字典序相等,最后一次得分是谁的谁就赢
{
if(last==1)
cout<<"first"<<endl;
else
cout<<"second"<<endl;
}
}
return 0;
}
C.
题目链接:http://codeforces.com/contest/493/problem/C
题意为:
a和b距离篮筐一段距离射篮,a射了n次,每次距离为a[i],b射了m次,每次距离为b[i], 给定一个界限d,如果射篮距离小于等于d的得2分,大于d的得3分,求最优的d,使得a的分数与b的分数之差最大化,如果最大化有多种情况,输出a的分数最高的那一组。 最后输出a的分数和b的分数。
一开始界限为0,即每个人的每求得分都为3,然后对a[i],b[i]依次从小到大进行排序,然后从小到大以b[i]为d, 计算出中间过程中的 a的总得分,b得总得分,更新最终答案的a的得分,b的得分。
代码:
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define ll long long
const int maxn=200002;
int a[maxn];
int b[maxn];
int na,nb;
ll scorea;
ll scoreb;
int main()
{
cin>>na;
for(int i=0;i<na;i++)
scanf("%d",&a[i]);
cin>>nb;
for(int i=0;i<nb;i++)
scanf("%d",&b[i]);
sort(a,a+na);
sort(b,b+nb);
scorea=na*3;
scoreb=nb*3;
ll ta=scorea,tb=scoreb;
int before=0;
int cur;
for(int i=0;i<nb;i++)
{
tb-=1;//以b[i]为界限
cur=upper_bound(a,a+na,b[i])-a;//找出第一个大于b[i]的位置
ta-=(cur-before);
before=cur;
if(scorea-scoreb<ta-tb||(scorea-scoreb==ta-tb&&ta>scorea))
{
scorea=ta;
scoreb=tb;
}
}
cout<<scorea<<":"<<scoreb;
return 0;
}
D.
题目链接:http://codeforces.com/contest/493/problem/D
题意为:有n*n的棋盘,白方在左上角(1,1)处,黑方在右上角(1,n)处,二者每一步可以上下左右,对角线走,一方抓到另一方则胜,双方都采用最优策略,如果黑方胜,输出black,如果白方胜,先输出 white,再输出第一步走到的坐标.
如果n为奇数,那么白方无论怎么走,黑方走的都和它对称,黑方肯定赢,如果n为偶数,那么白方只要走到 (1,2)这个坐标,就转换成了n为奇数的情况,白方必胜。
代码:
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define ll long long
int main()
{
int n;
cin>>n;
if(n&1)
cout<<"black";
else
{
cout<<"white"<<endl;
cout<<"1 2";
}
return 0;
}