1 条题解

  • 0
    @ 2026-2-10 16:08:49

    C :

    #include<stdio.h>
    int main()
    {
    int n,m;
         while(scanf("%d%d",&n,&m)!=EOF)
    	 {
         if((m>=2*n)&&(m<=4*n)&&(m%2==0))
            printf("%d %d\n",2*n-m/2,m/2-n);
         else
    	    printf("No\n");
          }
         return 0;
     }
    

    C++ :

    #include<stdio.h> 
    #include<math.h> 
    int main()
    {
      int a,b,c,d;
      scanf("%d%d",&a,&b);
      if(a>b/2||b%2!=0||a%1!=0||a<0||b<0||a*4<b)
      {
        printf("No");
      }
      else
      {
        c=b/2-a;
        d=a-c;
        printf("%d %d",d,c);
      }
    }
    

    Pascal :

    var
     n,m,t:longint;
    begin
     read(n,m);
     t:=m-n*2;
     if  (t mod 2=0) and (t>=0) and (t div 2<=n) then write(n-t div 2,' ',t div 2)
     else write('No');
    end.
    
    

    Java :

    import java.util.Scanner;
    
    public class Main {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt(); 
            int m = sc.nextInt(); 
    
            if (m % 2 != 0 || m < 2 * n || m > 4 * n) {
                System.out.println("No");
                return;
            }
    
            int rabbit = (m - 2 * n) / 2;
            int chicken = n - rabbit;
    
            if (rabbit >= 0 && chicken >= 0) {
                System.out.println(chicken + " " + rabbit);
            } else {
                System.out.println("No");
            }
        }
    }
    
    

    Python :

    # coding=utf-8
    #python2
    n,m = map(int,raw_input().split())
    c = 0
    for i in range(n,0,-1):
        if 2*i+4*(n-i)==m:
            c += 1
            break
    if c==0:
        print("No")
    else:
        print('%d %d' %(i,n-i))
    

    C# :

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.InteropServices;
    using System.Security.Cryptography;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApp2
    {
        internal class Program
        {
            static void Main()
            {
                /*int r = 0;
                int[] days = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
                string[] O  = Console.ReadLine().Split('-');
                int year =Convert.ToInt16( O[0]);
                int m = Convert.ToInt16(O[1]);
                int d = Convert.ToInt16(O[2]);
                if ( (year%4==0 && year%100!=0 )|| year%400==0 ) {
                    days[1] += 1;
                    for (int i = 0; i < m-1; i++) {
                    r += days[i];
                    }
                   
                    
                }
                else
                {
                    for (int i = 0; i < m - 1; i++)
                    {
                        r += days[i];
                    }
                }
                r += d;*/
    
    
    
                /*  string[] str = Console.ReadLine().Split();
                  double a = Convert.ToDouble(str[0]);
                  double b = Convert.ToDouble(str[1]);
                  double c = Convert.ToDouble(str[2]);
                  double k = b * b - 4 * a * c;
                  if (a == 0)
                  {
                      if (b == 0)
                      {
                          Console.WriteLine("No");
                      }
                      else
                      {
                          Console.WriteLine((-c / b).ToString("0.000000"));
                      }
                  }
    
                  else
                  {
                      if ((k) > 0)
                      {
                          double x1 = (-b - Math.Sqrt(k)) / 2 / a;
                          double x2 = (-b + Math.Sqrt(k)) / 2 / a;
                          if (x1 > x2)
                          {
                              Console.WriteLine(x1.ToString("0.000000"));
                              Console.WriteLine(x2.ToString("0.000000"));
                          }
                          else
                          {
                              Console.WriteLine(x2.ToString("0.000000"));
                              Console.WriteLine(x1.ToString("0.000000"));
                          }
                      }
                      else if (k == 0)
                      {
                          double x = -b / a / 2;
    
                          Console.WriteLine(x.ToString("0.000000"));
                      }
                      else
                      {
                          string T = "No";
                          Console.WriteLine(T);
                      }
                  }
                */
                string[] str = Console.ReadLine().Split();
                double n = Convert.ToDouble(str[0]);
                double m = Convert.ToDouble(str[1]);
                bool Ans = false;
                for (int ji = 1; ji < n; ji++)
    
                {
                    for (int tu = 1; tu < n; tu++)
                    {
                        int x = ji * 2 + tu * 4;
                        int y = ji + tu;
                        if (x == m && y == n)
                        {
    
                            Console.WriteLine(ji+" "+tu);
    
                            Console.ReadLine();
                           Ans = true;
                        }
                       
                    }
                }
                if (Ans == false) { Console.WriteLine("No"); ; }
    
    
    
                Console.ReadKey();
         
            }
        }
    }
    
    • 1

    信息

    ID
    33
    时间
    1000ms
    内存
    128MiB
    难度
    3
    标签
    递交数
    0
    已通过
    0
    上传者