245 条题解

  • 0
    @ 2015-08-25 09:43:05

    这题标签为啥是贪心?不是模拟么。。
    ps:此题只是数据水而已

  • 0
    @ 2015-08-20 13:29:55

    好水……
    #include <cstdio>
    int main() {
    //freopen("data.txt","r",stdin);
    int n,k;scanf("%d%d",&n,&k);
    int m=0,temp=0;
    for(int i=1;i<=n;) {
    int x;scanf("%d",&x);
    if(x!=i && x) temp++;
    else if(!x) {
    if(temp>=k) m++;
    temp=0;i++;
    }
    }
    printf("%d",m);
    return 0;
    }

  • 0
    @ 2015-08-16 21:38:57

    program P1021;
    var
    select:array[1..200] of Boolean;
    talk:array[1..200,1..200] of Boolean;
    friend:array[1..200] of Integer;
    size,limit,i,j:integer;
    flag:boolean;
    function relax:boolean;
    var
    i:integer;
    begin
    relax:=true;
    for i:=1 to size do
    begin
    if (friend[i]<limit) and (select[i]) then
    begin
    relax:=false;
    select[i]:=false;
    for j:=1 to size do
    begin
    if talk[i,j] then
    begin
    friend[j]:=friend[j]-1;
    end;
    end;
    end;
    end;
    end;
    begin
    readln(size,limit);
    for i:=1 to size do
    begin
    for j:=1 to size do
    begin
    talk[i,j]:=false;
    end;
    end;
    for i:=1 to size do
    begin
    select[i]:=true;
    end;
    for i:=1 to size do
    begin
    read(j);
    while j<>0 do
    begin
    talk[i,j]:=true;
    read(j);
    end;
    end;
    for i:=1 to size do
    begin
    friend[i]:=0;
    end;
    for i:=1 to size do
    begin
    for j:=1 to size do
    begin
    if talk[i,j] then
    begin
    inc(friend[j]);
    end;
    end;
    end;
    repeat
    flag:=relax;
    until flag;
    j:=0;
    for i:=1 to size do
    begin
    if select[i] then
    begin
    inc(j);
    end;
    end;
    writeln(j);
    end.

    一开始将所有人都邀请,预处理算出每个人的同伴数目。再一遍一遍的检查,如果某个人的同伴数目不够,就不用邀请他了,然后再减少这个人的同伴的同伴数目,直到没有人被取消邀请为止。

  • 0
    @ 2015-07-13 15:31:51

    #include"iostream"
    #include<cstdio>
    #include<cstring>
    using namespace std;
    typedef long long ll;
    const int N=205;
    int ans;
    int n,k;
    int main()
    {
    cin>>n>>k;
    int i=1;
    int j;
    int num;
    while(i<=n)
    {
    num=0;
    cin>>j;
    while(j!=0)
    {
    num++;
    cin>>j;
    }
    if(num>=k)
    ans++;
    i++;

    }
    cout<<ans;
    return 0;
    }

  • 0
    @ 2015-05-26 19:09:45

    #include <iostream>
    using namespace std;

    int main(){
    int n;
    int k;
    cin >> n >> k;
    int result = 0;
    for(int i = 1; i <= n; i++){
    int count = 0;
    while(1){
    int temp;
    cin >> temp;
    if(temp != 0)
    count++;
    else{
    if(count >= k)
    result++;
    break;
    }
    }
    }
    cout << result << endl;
    }

  • 0
    @ 2015-03-24 07:38:19

    不用判断重复吗?。。数据好弱

  • 0
    @ 2015-01-15 18:07:48

    此题不是说要在舞会上至少找到K个人交流么。

    那么好,比如有个人能找到3个人聊天。(假设至少2个即可),那么如果那3个人都只能找到这个人聊天,这3个人就满足不了要求了,不就得走??既然走了不就不在舞会,这个人不就跟谁都交流不了也要排除么??求解

    求解答疑惑

    举例,1和2,1和3,1和4都是朋友,至少要2个人交流,就是K=2的时候,2 3 4都不符合要求,去不了舞会,所以1不是此事也不符合了么,因为2 3 4不在啊~

    此题题意不清吧。。光说在N个人里找符合要求的好像不太完善

  • 0
    @ 2014-11-25 17:34:21

    #include<iostream>
    #include<cstdio>
    using namespace std;
    int main()
    {
    int n,k,count=0; //count记录总人数
    int name,namecount; //namecount记录找到的交流人数
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
    namecount=0;
    while(1)
    {
    cin>>name;
    if(name==0) break;
    else namecount++;
    }
    if(namecount>=k)
    count++;
    }
    cout<<count<<endl;
    return 0;
    }

  • 0
    @ 2014-11-04 15:39:02

    这题目介绍太坑了。。。。
    问题来了:
    只有其中M个人去的话,这M个人和不去的人关系就要减少。那就不到k个人了。。。题目蛋疼。。
    不按照题意的AC写法:
    #include <stdio.h>
    #include <iostream>
    using namespace std;

    int num[201]={0};

    int main(){
    int n,k;
    cin>>n>>k;
    int i,j;
    for(i=1;i<=n;++i){
    int x;
    cin>>x;
    while(x!=0){
    num[i]++;
    cin>>x;
    }
    }
    int tot=0;
    for(i=1;i<=n;++i){
    if(num[i]>=k)
    tot++;
    }
    printf("%d",tot);
    }
    按题意写的TE写法:
    #include <stdio.h>
    #include <iostream>
    using namespace std;

    int con[201][201]={0},num[201]={0};

    int main(){
    int n,k;
    cin>>n>>k;
    int i,j;
    for(i=1;i<=n;++i){
    int x;
    cin>>x;
    while(x!=0){
    con[i][x]=1;
    num[i]++;
    cin>>x;
    }
    }
    int flag=1;
    while(flag==1){
    flag=0;
    for(i=1;i<=n;++i){
    if(num[i]<k){
    for(j=1;j<=n;++j){
    if(con[j][i]==1){
    con[j][i]=0;
    num[j]--;
    }
    }
    num[i]=0;
    flag=1;
    }
    }
    }
    int tot=0;
    for(i=1;i<=n;++i){
    if(num[i]!=0)
    tot++;
    }
    printf("%d",tot);
    }

  • 0
    @ 2014-10-29 16:00:46

    NOIP2014赛前AC留念
    (人家都不好意思留念了呢
    为了调节调节紧张的刷题气氛,特刷此水题!)
    (这竟然是100AC……)
    var n,k,i,ans,tot,ch:longint;
    begin
    readln(n,k);
    for i:=1 to n do
    begin
    tot:=0;
    read(ch);
    while ch<>0 do
    begin
    inc(tot);
    read(ch);
    end;
    if tot>=k then inc(ans);
    end;
    writeln(ans);
    end.

  • 0
    @ 2014-10-22 18:21:21

    提高AC率的好题。。。。

  • 0
    @ 2014-08-24 03:34:23

    var
    ans,x,n,tot,i,k:longint;
    begin
    tot:=0;
    readln(n,k);
    for i:=1 to n do
    begin
    read(x);
    while x<>0 do
    begin
    inc(tot);
    read(x);
    end;
    if tot>=k then inc(ans);
    end;
    writeln(ans);
    end.

    什么心态啊!居然忘记初始化WA了一次 我的AC率啊= =

  • 0
    @ 2014-08-05 17:33:10

    var
    n,k,hmc:integer;
    partner,renshu,xh:longint;
    begin
    readln(n,k); {读入初始数据}
    for xh:=1 to n do
    begin
    hmc:=1;
    partner:=1;
    while (hmc<>0) do
    begin
    read(hmc);
    if hmc<>0 then partner:=partner+1; {读入并累加}
    end;
    readln;
    if partner>=k then renshu:=renshu+1; {判断}
    end;
    writeln(renshu);
    end.

  • 0
    @ 2014-05-06 13:36:47

    var
    n,i,max,k,m,x:integer;
    begin
    readln(n,k);
    for i:=1 to n do
    begin
    max:=0;
    read(x);
    while x<>0 do
    begin
    inc(max);
    read(x);
    end;
    if max>=k then inc(m);
    end;
    writeln(m);
    end.

  • 0
    @ 2014-05-06 13:36:16

    var
    n,i,max,k,m,x:integer;
    begin
    readln(n,k);
    for i:=1 to n do
    begin
    max:=0;
    read(x);
    while x<>0 do
    begin
    inc(max);
    read(x);
    end;
    if max>=k then inc(m);
    end;
    writeln(m);
    end.

  • 0
    @ 2014-04-25 13:26:24

    我都没开数组,直接用integer读入看看是不是0,然后统计一下人数,10分钟轻松AC。
    var n,i,j,k,m,a:integer;
    begin
    readln(n,k);
    for i:=1 to n do begin
    j:=0;
    read(a);
    if a<>0 then repeat
    j:=j+1;
    read(a);
    until a=0;
    if j>=k then m:=m+1;
    end;
    writeln(m);
    end.

  • 0
    @ 2014-04-07 15:04:46

    此题什么心态??

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

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

  • 0
    @ 2013-10-25 19:12:10

    var
    n,k,i,x,sum:longint;
    st:array[1..200]of longint;

    begin
    readln(n,k);
    for i:=1 to n do
    st[i]:=-1;
    for i:=1 to n do
    begin
    while not eoln do
    begin
    read(x);
    inc(st[i]);
    end;
    readln;
    end;
    sum:=0;
    for i:=1 to n do
    if st[i]>=k then
    inc(sum);
    writeln(sum);
    end.

信息

ID
1021
难度
3
分类
贪心 点击显示
标签
递交数
6422
已通过
3220
通过率
50%
被复制
23
上传者