A. Tiling with Hexagons
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int a,b,c,ans;
while(~scanf("%d%d%d",&a,&b,&c))
{
ans=(a+c-1)*(b+c-1)-(1+c-1)*(c-1);
cout<<ans<<endl;
}
return 0;
}
B. Forming Teams
#include <iostream>
#include<stdio.h>
#define N 110
using namespace std;
int father[110],vis[110],num[110];
int n,m,a,b;
int find(int x)
{
if(x!=father[x])
return father[x]=find(father[x]);
}
int main()
{
int i,c,fa,fb;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(i=1;i<=n;i++)
{
vis[i]=0;
num[i]=1;
father[i]=i;
}
for(i=1;i<=m;i++)
{
scanf("%d%d",&a,&b);
fa=find(a);
fb=find(b);
if(fa==fb)
{
vis[fa]=1;
vis[fb]=1;
}
if(fa!=fb)
{
father[fa]=fb;
num[fb]+=num[fa];
}
}
c=0;
for(i=1;i<=n;i++)
{
if(father[i]==i&&vis[i]==1)
c+=num[i]%2;
}
cout<<n-(n-c)/2*2<<endl;
}
return 0;
}