192 条题解

  • 4
    @ 2017-09-02 19:24:33

    stl大法好

    应该很容易看懂吧

    直接上代码

    #include<iostream>
    #include<cstdio>
    #include<map>
    #include<algorithm>
    #include<cstring>
    using namespace std;
    int n;
    struct node{
        string s;
        int x,y;
    }a[12];
    map <string,int> q;
    int main(){
        scanf("%d",&n);
        for(int i=1;i<=n;i++){
            cin>>a[i].s;
            q[a[i].s]=i;
        }
        for(int i=1;i<=n;i++){
            string s1,s2;
            int m,k;
            cin>>s1;
            scanf("%d%d",&m,&k);
            if(k==0) continue;
            a[q[s1]].x+=m/k*k;
            m/=k;
            for(int j=1;j<=k;j++){
                cin>>s2;
                a[q[s2]].y+=m;
            }
        }
        for(int i=1;i<=n;i++){
            cout<<a[i].s<<" ";
            printf("%d\n",a[i].y-a[i].x);
        }
        return 0;
    }
    
  • 1
    @ 2018-07-30 16:24:09

    no sofa...

  • 1
    @ 2017-05-07 13:03:11
    /*
    此题简单模拟,但也有细节要注意:
    1.人数有可能为0,在处理剩余钱时要判断人数是否为0,
    不然会出现除以0的情况
    2.老问题了,可能是做题少,双重循环的自加条件,
    总是容易将内循环自加写成外循环自加
    3.注意num数组的找分钱人时的方法
    总而言之,虽然这类题目简单,但竟然还做了很久,
    应该多做点题锻炼一下基础能力了,不能贪图高级算法了
    */
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    #include <string>
    using namespace std;
    
    struct node
    {
        string name;
        int out,friends,in;
        int num[11];
    }a[12];
    int n;
    
    int find(string b)
    {
        for(int i=1;i<=n;i++)
            if(a[i].name==b)
                return i;
        return 0;
    }
    
    int main()
    {
        cin>>n;
        for(int i=1;i<=n;i++)
            cin>>a[i].name;
        string b;
        for(int i=1;i<=n;i++)
        {
            cin>>b;
            int x=find(b);
            cin>>a[x].out>>a[x].friends;
            for(int j=1;j<=a[x].friends;j++)
            {
                cin>>b;
                a[x].num[j]=find(b);
            }
        }
        for(int i=1;i<=n;i++)
        {
            if(a[i].friends==0)
                continue;
            int k=a[i].out/a[i].friends;
            a[i].out=k*a[i].friends;
            for(int j=1;j<=a[i].friends;j++)
                a[a[i].num[j]].in+=k;
        }
        for(int i=1;i<=n;i++)
            cout<<a[i].name<<" "<<a[i].in-a[i].out<<endl;
        return 0;
    }
         
    
  • 0
    @ 2020-08-21 11:11:30
    #include<iostream>
    #include<map>
    #define FOR(i,a,b) for(int i=a;i<=b;i++)
    using namespace std;
    const int N=20;
    map<string,int>a;
    map<string,int>::iterator it;
    int n,m,p;
    string s,name[12];
    int main()
    {
        cin>>n;FOR(i,1,n)cin>>name[i];
        FOR(i,1,n)
        {
            cin>>s>>m>>p;
            int v;
            if(p==0)continue;
            v=m/p;
            a[s]-=v*p;
            FOR(j,1,p)
            {
                cin>>s;
                a[s]+=v;
            }
        }
        FOR(i,1,n)
            cout<<name[i]<<" "<<a[name[i]]<<endl;
        return 0;
    }
    
    
  • 0
    @ 2020-04-12 22:35:18
    #include <iostream>             //[USACO]贪婪的送礼者
    #include <algorithm>
    #include <string>
    #include <unordered_map>
    using namespace std;
    
    int main()
    {
        unordered_map<string, int> m;
        string str;
        int NP, tatol, n;
        cin >> NP;
        string N[10];
        for (int i = 0; i < NP; i++)
        {
            cin >> str;
            N[i] = str;
            m[str] = 0;
        }
    
        for (int i = 0; i < NP; i++)
        {
            cin >> str >> tatol >> n;
            int k;
            if(n)
                k = tatol / n;
            m[str] -= k * n;
    
            for (int i = 0; i < n; i++)
            {
                cin >> str;
                m[str] += k;
            }
        }
    
        for (int i = 0; i < NP; i++)
            cout << N[i] << " " << m[N[i]] << endl;
    
        return 0;
    }
    
    
  • 0
    @ 2018-09-01 12:04:05

    之前用c语言写不知道为什么一直不行,受到大佬启发,用map试了一下。
    可以说是本弱智儿童做出第一道题。
    一下是我的代码。
    #include<iostream>
    #include<map>
    #include<cstring>
    using namespace std;
    int main()
    {
    int money, rest, k, num;
    char name[10][20];
    map<string, int> p;
    cin >> num;
    for (int i = 0; i < num; i++) {
    cin >> name[i];
    p.insert(pair<string,int>(name[i],0));
    }
    for (int i = 0; i < num; i++) {
    char receive_name[20];
    char temp_name[20];
    cin >> temp_name;
    cin >> money >> k;
    if (k == 0) continue;
    else {
    rest = money - (money / k)*k;
    }
    for (int j = 0; j < k; j++) {
    cin >> receive_name;
    p[receive_name] += (money / k);
    }
    p[temp_name] += rest;
    p[temp_name] -= money;
    }
    for (int i = 0; i < num; i++)
    cout << name[i] << " " << p[name[i]]<<endl;
    return 0;
    }

  • 0
    @ 2018-08-02 12:28:42

    哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈

  • 0
    @ 2017-02-27 10:48:54
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<iostream>
    using namespace std;
    int n;
    struct peo
    {
        char name[30];
        int money;
        int income;
    };
    void solve()
    {
        peo list[50];
        scanf("%d",&n);
        for(int i=0;i<n;i++)
        {
            scanf("%s",list[i].name);
            list[i].money=0;
            list[i].income=0;
        }
        for(int i=0;i<n;i++)
        {
            int num,sig,pos;
            char tmpname[30];
            scanf("%s",tmpname);
            for(pos=0;pos<n;pos++)
            {
                if(strcmp(tmpname,list[pos].name)==0)
                {
                    break;
                }
            }
            scanf("%d %d",&list[pos].money,&num);
            if(num==0)
            {
                continue;
            }
            else
            {
                sig=list[pos].money/num;    
            }
            list[pos].income+=list[pos].money-sig*num;
            for(int j=0;j<num;j++)
            {
                char str[30];
                int lp;
                scanf("%s",str);
                for(lp=0;lp<n;lp++)
                {
                    if(strcmp(str,list[lp].name)==0)
                    {
                        break;
                    }
                }
                list[lp].income+=sig;
            }
        }
        for(int i=0;i<n;i++)
        {
            printf("%s %d\n",list[i].name,list[i].income-list[i].money);
        }
    }
    int main()
    {
        solve();
        return 0;
    }
    
  • 0
    @ 2015-02-28 10:17:22

    太简单了,秒杀这题。。。。。。 哈
    program e1035;
    var n,i,j,x,y,t,k,b:longint;
    d,e,f:array[1..100000]of longint;
    a:array[1..10000]of string; s,c:string;
    begin
    // assign(input,'1.txt');
    // reset(input);
    readln(n);
    for i:=1 to n do
    readln(a[i]);
    for i:=1 to n do
    begin
    readln(s);
    for j:=1 to n do
    if s=a[j] then
    begin
    t:=j;
    break;
    end;
    readln(b,k);
    if k<>0 then
    begin
    for j:=1 to n do
    if s=a[j] then
    begin
    f[t]:=f[t]-b+b mod k;
    break;
    end;
    for j:=1 to k do
    begin
    readln(s);
    for x:=1 to n do
    if s=a[x] then
    begin
    f[x]:=f[x]+b div k;
    break;
    end;
    end;
    end;
    end;
    for i:=1 to n do
    writeln(a[i],' ',f[i]);
    end.

  • 0
    @ 2015-02-28 10:15:53

    program e1035;
    var n,i,j,x,y,t,k,b:longint;
    d,e,f:array[1..100000]of longint;
    a:array[1..10000]of string; s,c:string;
    begin
    // assign(input,'1.txt');
    // reset(input);
    readln(n);
    for i:=1 to n do
    readln(a[i]);
    for i:=1 to n do
    begin
    readln(s);
    for j:=1 to n do
    if s=a[j] then
    begin
    t:=j;
    break;
    end;
    readln(b,k);
    if k<>0 then
    begin
    for j:=1 to n do
    if s=a[j] then
    begin
    f[t]:=f[t]-b+b mod k;
    break;
    end;
    for j:=1 to k do
    begin
    readln(s);
    for x:=1 to n do
    if s=a[x] then
    begin
    f[x]:=f[x]+b div k;
    break;
    end;
    end;
    end;
    end;
    for i:=1 to n do
    writeln(a[i],' ',f[i]);
    end.

  • 0
    @ 2015-01-09 18:53:14

    我擦,又是这样,不好好看题目,没看到还有保留钱,没一次AC,丢脸了。这都多少次了,诶,下次一定要耐心看题目!!!!!!!

    总之不废话,简单的模拟即可,自己别看晕了就好,字符串程序的读入有点恶心。

    ###Bolck code

    program P1035;
    var a,np,i,num,j,np2:longint; sentter,getter:string;
    money:array[1..10] of longint;
    names:array[1..10] of string;
    function find(x:string):longint;
    var i:longint;
    begin
    for i:=1 to np do
    if x=names[i] then
    exit(i);
    end;

    begin //main
    //assign(input,'shuju.in'); reset(input);

    readln(np); fillchar(money,sizeof(money),0);
    for i:=1 to np do readln(names[i]);

    for i:=1 to np do
    begin
    readln(sentter); read(num); readln(np2);
    a:=find(sentter);

    money[a]:=money[a]-num;
    if np2<>0 then
    money[a]:=money[a]+(num mod np2);

    for j:=1 to np2 do
    begin
    readln(getter); a:=find(getter); money[a]:=money[a]+(num div np2);
    end;
    end;

    for i:=1 to np do
    begin
    write(names[i],' '); writeln(money[i]);
    end;
    //close(input);
    end.

    • @ 2015-01-09 18:58:19

      注解:find函数用来搜索这个人是第几个人在数据,因为发礼物的时候顺序不一样- -当然你也可以离线处理,随便啦反正就10个人

  • 0
    @ 2014-10-27 21:03:17

    #include<stdio.h>
    #include <string.h>

    struct student
    {

    char name[14];
    int h_money;
    int s_money;
    int g_money;
    }a[10];

    int main()
    {
    int n,i,j,m,k,r;
    int result;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
    scanf("%s",a[i].name);
    }
    for(i=0;i<n;i++)
    {
    char temp_name[15]={0};
    scanf("%s",temp_name);
    for(j=0;j<n;j++)
    {
    if (strcmp(a[j].name,temp_name)==0)
    {
    scanf("%d%d",&a[j].h_money,&m);
    for(k=0;k<m;k++)
    {
    char g_money_name[15]={0};
    scanf("%s",g_money_name);
    for(r=0;r<n;r++)
    {
    if(strcmp(a[r].name,g_money_name)==0)
    {
    a[r].g_money=a[r].g_money+a[j].h_money/m;
    a[j].s_money=a[j].s_money+a[j].h_money/m;
    }
    }
    }
    }
    }
    }

    for(i=0;i<n;i++)
    {
    result=a[i].g_money-a[i].s_money;
    printf("%s %d\n",a[i].name,result);
    }

    return 0;
    }

  • 0
    @ 2014-10-27 11:15:48

    NOIP2014赛前AC留念
    var np,i,j,z,tip:longint;
    t:string;
    s,give:array[1..10] of string;
    peo,mon,num:array[1..50] of longint;

    begin
    //assign(input,'gift1.in');
    //assign(output,'gift1.out');
    //reset(input);
    //rewrite(output);
    readln(np);
    for i:=1 to np do
    readln(s[i]);
    for i:=1 to np do
    begin
    readln(t);
    for j:=1 to np do
    if t=s[j] then
    begin
    tip:=j;
    break;
    end;

    readln(mon[tip],peo[tip]);
    if peo[tip]<>0 then
    begin
    num[tip]:=num[tip]-mon[tip]+(mon[tip] mod peo[tip]);
    for j:=1 to peo[tip] do
    begin
    readln(give[j]);
    for z:=1 to np do
    if s[z]=give[j] then
    begin
    num[z]:=num[z]+(mon[tip] div peo[tip]);
    break;
    end;
    end;
    end;
    end;
    for i:=1 to np do
    writeln(s[i],' ',num[i]);
    //close(input);
    //close(output);
    end.

  • 0
    @ 2014-10-06 17:21:39

    #include<cstdio>
    #include<cstring>

    using namespace std;

    struct Person_node
    {
    char name[15];
    int Send_money,Receive_money,Receive_num;
    }Person[11];

    int N;

    int search(char *name)
    {
    for(int i=1;i<=N;i++)
    if (strcmp(name,Person[i].name)==0)
    return i;
    }

    int main()
    {
    memset(Person,0,sizeof(Person));
    scanf("%d\n",&N);
    for(int i=1;i<=N;i++)
    scanf("%s\n",Person[i].name);
    char name[15];
    for(int i=1;i<=N;i++)
    {
    scanf("%s\n",name);
    int id=search(name);
    scanf("%d\n%d\n",&Person[id].Send_money,&Person[id].Receive_num);
    if (Person[id].Send_money!=0)
    Person[id].Send_money-=Person[id].Send_money%Person[id].Receive_num;
    for(int j=1;j<=Person[id].Receive_num;j++)
    {
    scanf("%s\n",name);
    Person[search(name)].Receive_money+=Person[id].Send_money/Person[id].Receive_num;
    }
    }
    for(int i=1;i<=N;i++)
    printf("%s %d\n",Person[i].name,Person[i].Receive_money-Person[i].Send_money);
    return 0;
    }

  • 0
    @ 2014-09-07 14:23:58

    type rec=record
    a:string;
    b:longint;
    c:longint;
    end;
    var n,i,j,num,l,give:longint;
    s1,s2:string;
    s:array[1..10] of rec;
    begin
    readln(n);
    for i:=1 to n do readln(s[i].a);
    for l:=1 to n do begin
    readln(s1);
    give:=0;
    for j:=1 to n do begin
    if s[j].a=s1 then begin
    readln(s[j].b,num);
    if num=0 then break;
    give:=s[j].b div num;
    s[j].b:=give*num;
    end;
    end;
    for i:=1 to num do begin
    readln(s2);
    for j:=1 to n do begin
    if s[j].a=s2 then inc(s[j].c,give);
    end;
    end;
    end;
    for i:=1 to n do begin
    writeln(s[i].a,' ',s[i].c-s[i].b);
    end;
    end.

  • 0
    @ 2014-08-24 15:39:07

    type

    node=record

    name:string;

    min,mout:integer;

    end;

    var

    p:array[1..10]of node;

    n,m,x,i,j,k,t:integer;

    name,namem:string;

    begin

    readln(n);

    for i:=1to n do

    readln(p[i].name);

    for i:=1to n do

    begin

    readln(namem);

    for j:=1to n do if p[j].name=namem then begin

    t:=j;

    break;

    end;

    readln(m,x);

    for j:=1to x do

    begin

    readln(name);

    for k:=1to n do

    if p[k].name=name then begin

    inc(p[k].min,m div x);

    break;

    end;

    end;

    if x<>0then inc(p[t].mout,m-m mod x);

    end;

    for i:=1to n do

    writeln(p[i].name,' ',p[i].min-p[i].mout);

    end.

    发代码老是格式错误挤成一堆 所以我只好用打一行空一行这种恶心的办法==题目不难纯模拟但是要细心点……坑了我半天

  • 0
    @ 2014-08-02 16:26:07

    20题!!!

    记录信息
    评测状态 Accepted
    题目 P1035 贪婪的送礼者
    递交时间 2014-08-02 16:23:53
    代码语言 C++
    评测机 VijosEx
    消耗时间 15 ms
    消耗内存 272 KiB
    评测时间 2014-08-02 16:23:58
    评测结果
    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #2: Accepted, time = 15 ms, mem = 272 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 268 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 268 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 268 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 268 KiB, score = 10
    Accepted, time = 15 ms, mem = 272 KiB, score = 100

  • 0
    @ 2014-01-01 11:58:51

    Vijos 题解:http://hi.baidu.com/umule/item/2c997f8ed9600fdae596e017
    有疑问请留言 共同进步

  • 0
    @ 2014-01-01 11:57:34

    Vijos 题解:http://hi.baidu.com/umule/item/2c997f8ed9600fdae596e017
    有疑问请留言 共同进步

  • 0
    @ 2013-10-07 14:52:13

    var
    nam:array[0..11] of string;
    res:array[0..11] of longint;
    n,ger,rer,i,j,m,pay:longint;

    Function num:longint;
    begin num:=1; while (nam[num]<>nam[0]) do inc(num);
    end;

    begin
    readln(n);
    for i:=1 to n do readln(nam[i]);
    for i:=1 to n do begin
    readln(nam[0]); read(pay); readln(m);
    ger:=num; if m=0 then continue;
    res[ger]:=res[ger]-pay+pay mod m;
    pay:=pay div m;
    for j:=1 to m do begin
    readln(nam[0]); rer:=num;
    res[rer]:=res[rer]+pay;
    end;
    end;
    for i:=1 to n do writeln(nam[i],' ',res[i]);
    end.

信息

ID
1035
难度
2
分类
模拟 点击显示
标签
(无)
递交数
5222
已通过
2901
通过率
56%
被复制
19
上传者