山东省第八届ACM题(部分赛题整理)

版权声明:低调地前行,越努力越幸运! https://blog.csdn.net/SSYITwin/article/details/83307052
3893 - Return of the Nim 118 / 221 53.39% “浪潮杯”山东省第八届ACM大学生程序设计竞赛(感谢青岛科技大学)
  3894 - Quadrat 34 / 73 46.58% “浪潮杯”山东省第八届ACM大学生程序设计竞赛(感谢青岛科技大学)
  3895 - fireworks 195 / 635 30.71% “浪潮杯”山东省第八届ACM大学生程序设计竞赛(感谢青岛科技大学)
  3896 - HEX 97 / 212 45.75% “浪潮杯”山东省第八届ACM大学生程序设计竞赛(感谢青岛科技大学)
  3897 - news reporter 11 / 29 37.93% “浪潮杯”山东省第八届ACM大学生程序设计竞赛(感谢青岛科技大学)
  3898 - quadratic equation 332 / 1629 20.38% “浪潮杯”山东省第八届ACM大学生程序设计竞赛(感谢青岛科技大学)
  3899 - sum of power 388 / 1103 35.18% “浪潮杯”山东省第八届ACM大学生程序设计竞赛(感谢青岛科技大学)
  3900 - triangle 13 / 50 26.00% “浪潮杯”山东省第八届ACM大学生程序设计竞赛(感谢青岛科技大学)
  3901 - Parity check 283 / 722 39.20% “浪潮杯”山东省第八届ACM大学生程序设计竞赛(感谢青岛科技大学)
  3902 - company 279 / 1042 26.78% “浪潮杯”山东省第八届ACM大学生程序设计竞赛(感谢青岛科技大学)
  3903 - CF 154 / 406 37.93% “浪潮杯”山东省第八届ACM大学生程序设计竞赛(感谢青岛科技大学)

sum of power

import java.math.BigInteger;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        BigInteger sum = BigInteger.ZERO;
        BigInteger ans;
        for(int i = 1;i <= n;i++){
            ans =  BigInteger.ONE;
            for(int j = 1;j <= m;j++)
                ans = ans.multiply(BigInteger.valueOf(i));
            sum = sum.add(ans).mod(BigInteger.valueOf(1000000007));
        }
        System.out.println(sum);
    }
}

Parity check

//大表找规律,应为数据范围太大,所以考虑用java求解 
#include<bits/stdc++.h>
using namespace std;
long long f[10000];
int main()
{

	f[0]=0;
	f[1]=1;
	for(int i=2;i<=50;i++)
	   f[i]=f[i-1]+f[i-2];
	for(int i=0;i<=50;i++)
	  cout<<"i="<<i<<",f[i]="<<f[i]%2<<endl;
	return 0;
} 


import java.math.BigInteger;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
      
       BigInteger m=BigInteger.valueOf(3);
       while(in.hasNextBigInteger())
       {
    	   BigInteger n=in.nextBigInteger();
    	   if(n.mod(m).equals(BigInteger.valueOf(0)))
       	    System.out.println(0);
           else
       	     System.out.println(1);
       }
      
    }
}

Return of the Nim

博弈综合:尼姆博弈+威佐夫博弈

#include<bits/stdc++.h>
using namespace std;
const int namx=1e5+6;
int s[namx];
int main()
{
	int g;
	cin>>g;
	while(g--)
	{
		int n;
		memset(s,0,sizeof(s));
		cin>>n;
		for(int i=0;i<n;i++)
		   scanf("%d",&s[i]);
		if(n==2)
		{
			sort(s,s+2);
            double k = ((sqrt(5.0)+1.0)/2.0);
            if(floor((s[1]-s[0])*k)==s[0])
			{
                cout<<"Watson"<<endl;
            }
            else{
                cout<<"Sherlock"<<endl;
            }
   
		}
		else
		{
			int ans=s[0];
			for(int i=1;i<n;i++)
			  ans=ans^s[i];
			if(ans==0)
			   cout<<"Watson"<<endl;
			else
			  cout<<"Sherlock"<<endl;
		}
	}
	return 0;
} 

quadratic equation

//当且仅当 x 为整数时, a * x * x + b * x + c = 0成立; 前真后假为假,其余全为真 
#include<bits/stdc++.h>
using namespace std;
double x1,x2;
int FindX(int a,int b,int c)
{
    //如果a不为0 && 求根公式小于0,说明没有解,返回false
    if(a && ((b * b - 4 * a * c) < 0))
        return false;
    if(a)//如果a不为0,求根公式算出x1,x2
	{
        x1 = (-1.0 * b + sqrt((b * b - 4 * a * c))) / (2 * a);
        x2 = (-1.0 * b - sqrt((b * b - 4 * a * c))) / (2 * a);
    }
    else if(!a)//如果a为0
	{
        if(b)//如果a为0,算出x1 = x2的值
            x1 = x2 = (-1.0 * c) / b;
        else
		{
            if(!c)
                return true;
            return false;
        }
    }
    return true;
}
bool judge(int a,int b,int c)
{
    //如果a为0 && b为0,或者全都为0,x可以取任意值,可以不是整数,返回false
    if((!a && !b) || (!a && !b && !c))
        return false;
    if(x1 == (int)x1 && x2 == (int)x2)//验证求到的x是整数 
        return true;
    return false;
}
int main()
{
    int n,a,b,c;
    scanf("%d",&n);
    while(n--)
	{
        scanf("%d%d%d",&a,&b,&c);
        x1 = 0,x2 = 0;
        if(FindX(a,b,c)&&!judge(a,b,c))
		{
            printf("NO\n");
        }
        else
            printf("YES\n");
    }
    return 0;
}

CF

点击转到

猜你喜欢

转载自blog.csdn.net/SSYITwin/article/details/83307052