A - Contest; cf算分..int即可
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int q, w, e, r;
while(~scanf("%d%d%d%d", &q, &w, &e, &r))
{
int z = max( q * 3 / 10, q - q / 250 * e );
int x = max( w * 3 / 10, w - w / 250 * r );
if( z > x )
puts("Misha");
else if( z < x )
puts("Vasya");
else
puts("Tie");
}
return 0;
}
B - Misha and Changing Handles 求最开始的原名和最后的化名有多少对并输出
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
map < string, string > mp;
map < string, string > :: iterator it;
string cc, dd;
void init()
{
mp.clear();
}
int main()
{
int n;
cin.sync_with_stdio(0);
while( cin >> n )
{
init();
while( n-- )
{
cin >> cc >> dd;
it = mp.find(cc);
if( it == mp.end() )
{
mp[dd] = cc;
}
else
{
mp[dd] = it->second;
mp.erase(it);
}
}
cout << mp.size() << endl;
map < string, string > :: iterator it;
for( it = mp.begin(); it != mp.end(); it++ )
{
cout << it->second << " " << it->first << endl;
}
}
return 0;
}
C - Misha and Forest :给出森林的每个点的度数及其叶子节点的异或和,求出每条边的两点。异或和即为,比如1的相邻点有2 3 4,那么就是a = 2 ^ 3 ^ 4。
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1000010;
struct node{
int u, v;
}e[N];
int cnt;
int d[N], f[N];
stack<int> q;
int main()
{
int n;
while(~scanf("%d", &n))
{
while( !q.empty() )
q.pop();
cnt = 0;
for( int i = 0; i < n; i++ )
{
scanf("%d%d", &d[i], &f[i]);
if( d[i] == 1 )
q.push(i);
}
while( !q.empty() )
{
int now = q.top();
q.pop();
if( d[now] != 1 )
continue;
int tmp = f[now];
e[cnt].u = now;
e[cnt++].v = tmp;
d[tmp]--;
f[tmp] ^= now;
if( d[tmp] == 1 )
q.push(tmp);
}
printf("%d\n", cnt);
for( int i = 0; i < cnt; i++ )
printf("%d %d\n", e[i].u, e[i].v);
}
return 0;
}