1 条题解

  • 0
    @ 2024-5-10 0:45:58

    C :

    #include<stdio.h>
    int main()
    {
    	int VUL,D;
    	while(scanf("%d%d",&VUL,&D)!=EOF)
    	{
    		int i=1,t=0,s=0,count=0;
    		while(1)
    		{
    			s+=i*D;
    			count+=i;
    			if(s==VUL)
    			{
    				t=count+i-1;
    				break;
    			}
    			if((s+(i+1)*D)>VUL)
    			{
    				int d;
    				d=(VUL-s)%D?((VUL-s)/D+1):(VUL-s)/D;
    				t=count+i+d;
    				break;
    			}
    			else i++;
    		}
    		printf("%d\n",t);
    	}
    	return 0;
    }
    

    C++ :

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<map>
    #include<queue>
    #include<stack>
    #include<set>
    #include<vector>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    #define Max(a,b) (a > b ? a : b)
    #define Min(a,b) (a < b ? a : b)
    #define INF 0x3f3f3f3f
    #define M 100
    
    int judge(double n ,double d)
    {
        double ans = 0;
        for(int i = 1; ; i++)
        {
            ans += i * d;
            if(ans >= n)
            {
                return i;
            }
        }
    }
    
    int main()
    {
        double n,d;
        while(scanf("%lf%lf",&n,&d)!=EOF)
        {
            int ans = n / d + 0.9;
            ans += judge(n,d) - 1;
            printf("%d\n",ans );
        }
        return 0;
    }
    
    

    Pascal :

    program p1022;
    var s,i,j,k,t:longint;
        vul,d:longint;
    begin
      while not eof do
      begin
         readln(vul,d);
         s:=0; i:=0; t:=0;
         t:=vul div d;
         if d*t<vul then t:=t+1;
         while s<t do
          begin
            i:=i+1;  
            s:=s+i;
          end;
         writeln(t+i-1)
      end;
    end.
    
    

    Java :

    import java.util.Scanner;
    
    public class Main {
    
    	public static void main(String[] args) {
    		Scanner in = new Scanner(System.in);
    		while(in.hasNext()){
    			int vul = in.nextInt();
    			int d = in.nextInt();
    			int[] arr = new int[200];
    			arr[0] = d;
    			for(int i=1;i<arr.length;i++){
    				int tem =(i+1)*d;  
    				arr[i] = arr[i-1]+tem;
    				if(vul<=arr[i]){
    					if(d==arr[i])System.out.println(i+1+(vul+d-1)/d);
    					else System.out.println(i+(vul+d-1)/d);
    					break;
    				}
    			}
    		}
    	}
    
    }
    
    

    Python :

    import sys,math
      
    def check(n,d):
        Alist=[]
        j = int((2*n/d)**0.5+1)
        for i in xrange(1,j):
            if (i+1)*i*d <= 2*n:
                Alist.append(i)  
        k= max(Alist)
        if 2*n-k*(k+1)*d==0:
            print (k+1)*k/2+(k-1)
        elif n%d == 0:
            l = math.ceil(n/d-k*(k+1)/2)
            print k*(k+1)/2+k+int(l)
        else:
            l = math.ceil(n/d-k*(k+1)/2+1)
            print k*(k+1)/2+k+int(l)
    
    for line in sys.stdin:
        n,d = map(lambda x:int(x),line.split())
        check(n,d)
    

    C# :

    using System;
    using System.Collections.Generic;
    
    namespace BoP
    {
        class Program
        {
    
            static void Main(string[] args)
            {
                string line;
                while ((line = Console.ReadLine()) != null)
                {
                    string[] tokens = line.Split(' ');
                    int a = int.Parse(tokens[0]);
                    int b = int.Parse(tokens[1]);
                    int sum = a / b;
                    if (a % b != 0)
                    {
                        sum++;
                    }
                    int z = 1;
                    int x = 0;
                    while (x < sum)
                    {
                        x += z;
                        z++;
                    }
                    z--;
                    z--;
                    int sdfds = z;
                    int sdfdssdfsf = sdfds + sum;
                    Console.WriteLine(sdfdssdfsf);
                }
            }
        }
    }
    
    
    • 1

    信息

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