江西财经大学第一届程序设计竞赛

19 篇文章 0 订阅
13 篇文章 0 订阅
链接:https://www.nowcoder.com/acm/contest/115/B
来源:牛客网
给出一个出生日期,比如:1999-09-09, 问:从出生那一天开始起,到今天2018-04-21为止(包括出生日期和今天),有多少天,年月日都不包含数字4?    
输入描述:
第一行输入一个整数T(表示样例个数)接下来T组样例每个样例一行,包含一个字符串“yyyy-mm-dd”(1990<=yyyy<=2018)题目保证测试数据的正确性
输出描述:
输出题意要求的天数
 
示例1
 
输入
1
1999-09-09
 
输出
5020
Code:
#include <bits/stdc++.h>
using namespace std;
int a[20] = { 0 , 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 };
int check( int x ){
    if( x % 4 == 0 && x % 100 != 0 ) return 1;
    if( x % 400 == 0 ) return 1;
    return 0 ;
}
int judge( int x ){
    while( x ){
        int tmp = x % 10;
        if( tmp == 4 ) return 0;
        x /= 10;
    }
    return 1;
}
int main(){
    int T;
    cin >> T;
    int res ;
    int y,m,d;
    while( T-- ){
        int y,m,d;
        res = 0;
        scanf("%d-%d-%d",&y,&m,&d);
        if( y == 2018 ){
            for(int i = m + 1 ; i < 4 ; i++ ){
                res += a[i];    
                res -= 3;
            }
            res += a[m] - d + 1 ;
            if( d <= 4 ) res -= 3;
            else if( d <= 14 ) res -= 2;
            else if( d <= 24 ) res -= 1;
 
            if( m == 4 ) res = 0;
            cout << res << endl;
            continue;
        }
        if( judge(y) ){
            for( int i = m + 1 ; i <= 12 ; i++ ){
                if( i == 4 ) continue;
                if( i == 2 ){
                    if( check(y) ){
                        res += 29;
                    }else res += 28;
                }else  res += a[i];
                res -= 3;
            }
            if( m == 2 ){
                if( check(y) ) res += 29 - d + 1;
                else res += 28 - d + 1; 
            }else{
                res += a[m] - d + 1;
            }
            if( d <= 4 ) res -= 3;
            else if( d <= 14 ) res -= 2;
            else if( d <= 24 ) res -= 1;
        }
        for( int i = y + 1 ; i < 2018 ; i ++ ){
            if( !judge(i) )  continue;
            if( check(i) ) res += 366; 
            else res += 365;
            res -= 63;
        }
 
        res += 81;
        cout << res << endl;
    }
    return 0 ;
}

链接:https://www.nowcoder.com/acm/contest/115/F
来源:牛客网
题目描述


对于方程 2018 * x ^ 4 + 21 * x + 5 * x ^ 3 + 5 * x ^ 2 + 14 = Y, 告诉你Y的值,你能找出方程在0~100之间的解吗?
输入描述:
第一行输入一个正整数T(表示样例个数)接下来T组样例每组样例一行,输入一个实数Y
输出描述:
一行输出一个样例对应的结果,输出方程在0~100之间的解,保留小数点后4位小数;如果不存在,输出 -1

示例1

输入
2
1
20180421

输出
-1
9.9993
思路:二分。

Code:
#include <bits/stdc++.h>
#define INF 1e-7
using namespace std;

double fun( double x ){
	return 2018*x*x*x*x + 21 * x + 5 *x*x*x + 5*x*x+14;
}

int main(){
	int T;
	cin >> T;
	while( T-- ){
		double Y;
		cin >> Y;
		double l = 0.0 , r = 100.0;
		if( fun(l) > Y || fun(r) < Y ){
			cout<< -1 <<endl;
		}else{
			while( r - l > 1e-7 ){
				double mid = ( l + r ) / 2.0;
				double re = fun(mid);
				if( re > Y ){
					r = mid - 1e-7;
				}else{
					l = mid + 1e-7 ;
				}
			}
			printf("%.4lf\n", (l+r)/2.0);
		}

	}
	return 0;
}

链接:https://www.nowcoder.com/acm/contest/115/G
来源:牛客网
周末,小Q喜欢在PU口袋校园上参加各种活动刷绩点,体验丰富多彩的大学生活。    但是每个活动有各自的开始时间、结束时间、Happy值以及绩点数,活动之间可能存在时间冲突。    小Q是一个认真踏实的女孩,她在同一时间只会参加一个活动。    给出每一天的活动数,求小Q在同一天内所能获得的最大Happy值 与 绩点数。    小Q是一个活泼开朗的女孩,她总是寻求最大的Happy值,如果Happy值相同,才会尽可能使绩点数更多。 
输入描述:
第一行输入一个整数T(表示样例个数)接下来T组样例每组样例第一行输入一个整数N(表示有几项活动)接下来N行,每行输入s,e,h,p 4个整数,分别代表一个活动的开始时间、结束时间、Happy值以及绩点数0<=s<e<=24,1<=h,p<=100,1<=T,N<=20
输出描述:
 
COde:
#include <bits/stdc++.h>
using namespace std;
const int AX = 20+6;
struct Node{
	int s , e , h , p;
}a[AX];
bool cmp( const Node &a , const Node &b ){
	return a.s < b.s;
}
int happy[AX];
int scr[AX];
int main(){
	int T;
	cin >> T;
	int n;
	while( T-- ){
		cin >> n;
		for( int i = 0 ; i < n ; i++ ){
			cin >> a[i].s >> a[i].e >> a[i].h >> a[i].p; 
		}
		sort( a , a + n , cmp );
		memset( happy , 0 , sizeof(happy));
		memset( scr, 0 , sizeof(scr));
		for( int i = 0 ; i < n ; i++ ){
			for( int j = a[i].e ; j <= 24 ; j++ ){
				if( happy[a[i].s] + a[i].h > happy[j] ){
					happy[j] = happy[a[i].s] + a[i].h;
					scr[j] = scr[a[i].s] + a[i].p;
				}else if( happy[a[i].s] + a[i].h == happy[j] ){
					scr[j] = max( scr[j] , scr[a[i].s] + a[i].p ); 
				}
			}
		}
		cout << happy[24] << ' ' << scr[24] << endl;
	}
	return 0 ;
}
输出T行一行输出一个样例对应的结果小Q在一天内所能获得的最大 Happy值 与 绩点数
链接:https://www.nowcoder.com/acm/contest/115/H
来源:牛客网
晚上,小P喜欢在寝室里一个个静静的学习或者思考,享受自由自在的单身生活。    他总是能从所学的知识散发出奇妙的思维。    今天他想到了一个简单的阶乘问题,    0!= 1    1!= 1    2!= 1 * 2 = 2    3!= 1 * 2 * 3 = 6    4!= 1 * 2 * 3 *4 = 24    5!= 1 * 2 * 3 *4 * 5 = 120    。    。    如果 n=1000000000,那么n的阶乘会是多少呢,小P当然知道啦,那么你知道吗? 
输入描述:
第一行输入一个整数T(表示样例个数)接下来T组样例每组样例一行,输入一个整数N(0<=N<=1000000000)
输出描述:
输出T行每一行输出N的阶乘 N!(由于这个数比较大,所以只要输出其对1000000007取膜的结果即可)
 
示例1
 
输入
2
0
1000000000
 
输出
1
698611116
思路:分段打表1e7-1e9所有的阶乘存起来
Code:
#include <iostream>
#include <cstdio>
#define LL long long
using namespace std;
LL n;
const int p = 1e9+7;
LL a[110]={1,682498929,491101308,76479948,723816384,67347853,27368307,
	625544428,199888908,888050723,927880474,281863274,661224977,623534362,
	970055531,261384175,195888993,66404266,547665832,109838563,933245637,
	724691727,368925948,268838846,136026497,112390913,135498044,217544623,
	419363534,500780548,668123525,128487469,30977140,522049725,309058615,
	386027524,189239124,148528617,940567523,917084264,429277690,996164327,
	358655417,568392357,780072518,462639908,275105629,909210595,99199382,
	703397904,733333339,97830135,608823837,256141983,141827977,696628828,
	637939935,811575797,848924691,131772368,724464507,272814771,326159309,
	456152084,903466878,92255682,769795511,373745190,606241871,825871994,
	957939114,435887178,852304035,663307737,375297772,217598709,624148346,
	671734977,624500515,748510389,203191898,423951674,629786193,672850561,
	814362881,823845496,116667533,256473217,627655552,245795606,586445753,
	172114298,193781724,778983779,83868974,315103615,965785236,492741665,
	377329025,847549272,698611116};
	int main()
	{
		int T;
		cin >> T;
		while( T-- ){
			cin>>n;
			LL now=n/10000000;
			LL ans=a[now];
			for(LL i=now*10000000+1;i<=n;i++)
				ans=ans*i%p;
			cout<<ans%p <<endl;
			continue;

		}
		return 0;
	}
链接:https://www.nowcoder.com/acm/contest/115/I
来源:牛客网
题目描述
 
  小P和小Q是好朋友,今天他们一起玩一个有趣的游戏。    他们的初始积分都为1,赢的人可以将自己的分数乘以 (K的平方),而输的人也能乘以K。    他们玩的太开心了,以至于忘了自己玩了多久,甚至 K 是多少和游戏进行的回合数 N 都忘了。    现在给出他们俩最终的积分a,b,请问是否存在正整数K、N满足这样的积分,判断他们的游戏结果是否可信。 
输入描述:
第一行输入一个整数T(表示样例个数)接下来T组样例每组样例一行,输入两个正整数a,b(0<a,b<=1e9)
输出描述:
输出T行一行输出一个样例对应的结果若结果可信,输出 Yes否则,输出 No
 
示例1
 
输入
6
2 4
75 45
8 8
16 16
247 994
1000000000 1000000
思路:枚举立方数。(看题解又学到了新函数cbrt)
Code:
 
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int main(){
	int T;
	cin >> T;
	while( T-- ){
		LL a , b;
		cin >> a >> b;
		LL i ;
		for( i = 1 ; i < 1e6 ; i++ ){
			if( i * i * i == a * b ){
				cout << "Yes" << endl;
				break;
			}
		}
		if( i >= 1e6 ){
			cout << "No" << endl;			
		}
	}
	return 0 ;
}


 
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
#define LL long long
int main()
{
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
   int n;
   scanf("%d",&n);
   int cot=0;
   while(n--){
    LL a,b;
    scanf("%lld%lld",&a,&b);
    LL c = cbrt(a*b);
    LL aa = a / c;
    LL bb = b / c;
    if(aa * aa * bb == a && bb * bb * aa == b){
       puts("Yes");
    }else puts("No");
   }
   return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值