1月12日参加了自己的第一场CF比赛。结果还是比较惨的。比赛时只做出来两道,最后结束时B竟然没有通过,所以只是把A给做了。。罚分83。感觉很不好,先把能做的三道给整理一下吧。
A:水题,附代码:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main()
{
double a,b,c,d;
double sum1=0,sum2=0;
scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
sum1=max(3*a/10,a-(a/250)*c);
sum2=max(3*b/10,b-(b/250)*d);
if(sum1 > sum2)
printf("Misha\n");
else if(sum2 > sum1)
printf("Vasya\n");
else
printf("Tie\n");
return 0;
}
B:也是很脑残的一道题,但是最后竟然没过,而且花费时间有点多,感觉很不应该。思路很简单,就是string用的不够熟练。本身string是很方便的。但是调试的时候很麻烦最后索性改为了字符数组。但是竟然开小了,错也是错在了这里。。最后还是改为了字符数组A了。附代码:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cstring>
#include <map>
#define MAX_P 1003
using namespace std;
struct pep
{
string fir;
string last;
};
pep p[MAX_P];
int num;
int n;
int main()
{
scanf("%d",&n);
num=0;
string str1;
string str2;
int pos=-1;
for(int i = 0; i < n; i++)
{
cin>>str1>>str2;
for(int j = 0; j < num; j++)
{
if( p[j].last == str1 )
{
pos = j;
break;
}
if(j == num-1)
pos = -1;
}
if( pos != -1 )
p[pos].last = str2 ;
else
{
p[num].fir = str1 ;
p[num].last = str2 ;
num++;
}
}
printf("%d\n",num);
for(int i = 0; i < num; i++)
{
cout<<p[i].fir<<' '<<p[i].last;
if( i != num-1 )
printf("\n");
}
return 0;
}
代码2(map实现):
/*============================================*/
// Date: 2015/1/13
// Problem: codeforces
// Author: shinelin
// Memory: KB
// Time: ms
// Language: GNU C++
// To Be a Better Acmer.
/*============================================*/
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <cstring>
#include <string>
#include <list>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
using namespace std;
#define INF 0x7fffffff
#define LL long long
#define MAXN 1005
#define FI first
#define SE second
// #define DEBUG
const double pi = acos(-1.0);
const double eps = 1e-11;
map<string, string> ms;
map<string, string>::iterator it;
int main()
{
#ifdef DEBUG
freopen("input.txt", "r", stdin);
#endif
std::ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
string a, b;
cin >> n;
while(n --)
{
cin >> a >> b;
if(ms.find(a) == ms.end())
ms[b] = a;
else
{
ms[b] = ms[a];
ms.erase(a);
}
}
cout << ms.size() << endl;
for (it = ms.begin(); it != ms.end(); it ++)
cout << it->second << " " << it->first << endl;
// printf("\nTime used = %.2lf\n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}
C:这道题题意很不好想,有多个节点,每个节点有自己对应下标,提供两个信息。第一个数为该节点的度数,第二个数为该节点的所有相邻点的位置的与或和。要求输出所有边的位置信息。该开始没有思路,后来在学长的帮助下想到把每个度数为1的节点作为突破点,用队列逐个遍历度为1的点,每次输出度为1的点的临边时使父节点度减一,再利用(a^b)^a=b更新父节点的的第二个信息。如果此时该父节点度数为1就放入队列(防止链的情况),最终所有节点都会被遍历,所有度数>=1的点度数也将变为1。附代码:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cstring>
#include <queue>
#define INF 65537
using namespace std;
struct node
{
int first;
int next;
int pos;//记录初始位置
};
node vert[INF];
int n;
int main()
{
scanf("%d",&n);
int num=0;
//队列为int型,储存初始位置。最开始想用node,但是因为队列是拷贝信息,父节点数据没办法更新
queue<int> q;
int x;
for( int i = 0; i < n; i++)
{
scanf("%d%d",&vert[i].first,&vert[i].next);
num += vert[i].first;
vert[i].pos = i;
if( vert[i].first == 1)//将入度为1的放入队列
q.push( i );
}
//边数等于度数和/2
printf("%d\n",num/2);
while( !q.empty() )
{
x = q.front();
q.pop();
if( vert[x].first != 1 )
continue;
//对于度数为1的点本身第二个信息就是父节点位置
printf("%d %d\n",vert[x].pos,vert[x].next);
//父节点度数--
vert[vert[x].next].first--;
//更新父节点的第二个信息
vert[vert[x].next].next ^= vert[x].pos;
//将满足条件的点放入队列
if( vert[vert[x].next].first == 1 )
q.push( vert[x].next );
}
return 0;
}
总结:这是自己的第一次CF比赛,自己感觉做好两道题还是可以的,也不会罚分,但是时间还是太慢,再加上对string的不熟悉,最后结果还是比较惨的。感觉做CF比赛会比较有意思,跟平时的比赛比起来考思维也更多一点,以后会尽量坚持去参加每一次的比赛,希望自己的成绩也能越来越好。加油!