雕刻时光

just do it……nothing impossible
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

HIT summer training contest 08——练练手

Posted on 2011-08-01 22:37  huhuuu  阅读(439)  评论(0编辑  收藏  举报

在家没事干就要多做做比赛才是。。。

C题是搜索题 N个数字之间放N-1个"+","-","*" ,"/"

使每位不存在为k的数字。。。

注意点,超int,注意除数不为0,当结果为0是特判

View Code
//long long 注意0

#include
<stdio.h>
#include
<iostream>
#include
<algorithm>
#include
<string.h>
#include
<string>
#include
<set>
#include
<map>
usingnamespace std;

longlong a[10];
longlong Max;
longlong n,m;
longlong abc(longlong x)
{
if(x<0)return-x;
return x;
}

boolin(longlong a)
{
if(a==m)return0;
while(a>0)
{
if(m==a%10)
return0;
a
=a/10;
}

return1;
}

void dfs(longlong add,longlong step)
{
if(step==n)
{
if(in(add))
{
if(Max<add)
Max
=add;
}
return ;
}

dfs(add
+a[step],step+1);
dfs(abc(add
-a[step]),step+1);
dfs(add
*a[step],step+1);
if(a[step]!=0)
dfs(add
/a[step],step+1);
}

int main()
{
longlong i,t;
scanf(
"%lld",&t);
while(t--)
{

scanf(
"%lld%lld",&n,&m);

for(i=0;i<n;i++)
{
scanf(
"%lld",&a[i]);
}
Max
=-1;
dfs(a[
0],1);

if(Max==-1)
printf(
"No result\n");
else
printf(
"%lld\n",Max);
}
return0;
}

B选课,字符串处理题

一个人要是选了超过一门课就无效

先大写字符串,

{在连续输入小写字符串,set装}再 map对应下

发现输入小写字符串前面存在 过,删去对应选课人数(不过注意不要老是删,同种就删一次,bool 标记下)

View Code
#include<stdio.h>
#include
<iostream>
#include
<algorithm>
#include
<string.h>
#include
<string>
#include
<set>
#include
<map>
usingnamespace std;

bool hash[100][10000];

struct data
{
int no;
char ss[299];
}node1[
909];


bool cmp(data a,data b)
{
if(a.no==b.no)
return strcmp(a.ss,b.ss)<0;
return a.no>b.no;
}

struct stu
{
int no;
bool use;
};

int main()
{
char temp[299];
int add=-1;
set<string> set1;
gets(temp);

map
<string,stu>mm;

while(1)
{

if(temp[0]>='A'&&temp[0]<='Z')
{
add
++;
set<string> ss;
strcpy(node1[add].ss,temp);

while(gets(temp),(temp[0]<'A'||temp[0]>'Z')&&temp[0]!='1'&&temp[0]!='0')
{
ss.insert(temp);

}
if(temp[0]=='1'&&temp[0]=='0')break;

set<string>::iterator pp;

int all=0;
for(pp=ss.begin();pp!=ss.end();pp++)
{
if(mm.find(*pp)==mm.end())
{
mm[
*pp].no=add;
all
++;
}
else
{
if(mm[*pp].use==0)
{
node1[mm[
*pp].no].no--;
mm[
*pp].use=1;
}
}
}

node1[add].no
=all;

}
if(temp[0]=='1')
{
mm.clear();
int i;
sort(
&node1[0],&node1[add+1],cmp);
for(i=0;i<=add;i++)
{
printf(
"%s %d\n",node1[i].ss,node1[i].no);
}
for(i=0;i<=100;i++)
{
node1[i].no
=0;
}
add
=-1;
gets(temp);
}
if(temp[0]=='0')
return0;

}
}