zoukankan      html  css  js  c++  java
  • HIT summer training contest 08——练练手

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

    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;

    }
    }

      

  • 相关阅读:
    JAVA入门到精通-第42讲-坦克大战9
    JAVA入门到精通-第40讲-线程
    JAVA入门到精通-第37讲-事件总结-坦克大战5
    大数据 资源
    在线工具
    idea 添加 阿里代码规范
    idea 控制台中文乱码 解决方法
    idea 构建maven web项目
    oracle SQL 练习
    Oracle分页
  • 原文地址:https://www.cnblogs.com/huhuuu/p/2124348.html
Copyright © 2011-2022 走看看