题目链接:点击打开链接
第一题和第二题都是小数据和大数据都AC了,65分。。略高兴
思路请看各位大神的博客吧。。他们写的比我好
A:
#include <iostream>
#include <string>
#include <map>
#include <stdio.h>
using namespace std;
map<string,string> tp;
int main()
{
int testcase;
cin>>testcase;
for(int a=1;a<=testcase;a++)
{
tp.clear();
string tar[300];
int player,wordlen;
string t1,t2;
cin>>player>>wordlen;
for(int i=0;i<wordlen;i++)
{
cin>>t1>>t2;
tp.insert(make_pair(t1,t2));
}
int t=0;
char p;
while(1)
{
cin>>tar[t];
t++;
p=getchar();
if(p=='\n')
break;
}
map<string,string>::iterator it;
for(int i=1;i<player;i++)
{
for(int j=0;j<t;j++)
{
it=tp.find(tar[j]);
if(it!=tp.end())
{
tar[j]=it->second;
}
}
}
cout<<"Case #"<<a<<": ";
for(int i=0;i<t;i++)
{
if(i!=t-1)
cout<<tar[i]<<" ";
else
cout<<tar[i]<<endl;
}
}
return 0;
}
B:
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <math.h>
using namespace std;
int n,m,k;
void swap(long long &a,long long &b)
{
long long t=a;
a=b;
b=t;
}
long long getc(long long j)
{
return j*(j-1)/2;
}
int main()
{
int testcase;
int p=1;
cin>>testcase;
while (testcase--)
{
scanf("%d%d%d",&n,&m,&k);
if (n<m) swap(n,m);
int t=sqrt(k);
int b=t>m?m:t;
int a=k/b>n?n:k/b;
long long max=0;
for (;b>=2 && a<=n;--b,a=k/b)
{
long long sum=getc(a)*getc(b);
int p=k-a*b;
if (a<n)
{
sum=sum+getc(p)*a;
}
else
{
sum=sum+getc(p)*b;
}
max=max>sum?max:sum;
}
cout<<"Case #"<<p<<": "<<max<<endl;
p++;
}
return 0;
}