1 条题解

  • 0
    @ 2023-3-13 12:11:54

    C :

    #include<stdio.h>
    
    int main()
    {
    	int t,n,m,c1,c2,c5,k;
    	scanf("%d",&t);
    	while(t--)
    	{
    		scanf("%d%d",&n,&m);
    		k=0;
    		for(c5=0;5*c5<=m;c5++)
    			for(c2=0;2*c2+5*c5<=m;c2++)
    			{
    				c1=m-5*c5-2*c2;
    				if(c1+c2+c5==n)
    					k++;
    			}
    		printf("%d\n",k);
    	}
    	return 0;
    }
    

    C++ :

    #include<stdio.h>
    
    int main()
    {
    	int t,n,m,c1,c2,c5,k;
    	scanf("%d",&t);
    	while(t--)
    	{
    		scanf("%d%d",&n,&m);
    		k=0;
    		for(c5=0;5*c5<=m;c5++)
    			for(c2=0;2*c2+5*c5<=m;c2++)
    			{
    				c1=m-5*c5-2*c2;
    				if(c1+c2+c5==n)
    					k++;
    			}
    		printf("%d\n",k);
    	}
    	return 0;
    }
    

    Pascal :

    program p1025;
    var m,n,t,i,j,k,c,s:longint;
    begin
      readln(t);
      for c:=1 to t do
       begin
         readln(n,m); s:=0;
         for i:=0 to m do
          for j:=0 to (m div 2) do
            begin
              k:=n-i-j;
              if (i+j*2+k*5=m) and (k>=0) then s:=s+1;
            end;
         writeln(s);
        end;
    end.
    
    • 1

    信息

    ID
    2148
    时间
    1000ms
    内存
    32MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者