牛客练习赛18

A 题目描述 
这题要你回答T个询问,给你一个正整数S,若有若干个正整数的和为S,则这若干的数的乘积最大是多少?请输出答案除以2000000000000000003(共有17 个零) 的余数。
举例来说,当 S = 5 时,若干个数的和为 5 的情形有以下 7 种(不考虑数字的顺序的话):
1. 1 + 1 + 1 + 1 + 1
2. 1 + 1 + 1 + 2
3. 1 + 1 + 3
4. 1 + 2 + 2
5. 1 + 4
6. 2 + 3
7. 5
他们的乘积依序为:
1. 1 * 1 * 1 * 1 * 1 = 1
2. 1 * 1 * 1 * 2 = 2
3. 1 * 1 * 3 = 3
4. 1 * 2 * 2 = 4
5. 1 * 4 = 4
6. 2 * 3 = 6
7. 5 = 5
其中乘积最大的是 2 * 3 = 6。
输入描述:
输入的第一行有一个正整数 T,代表该测试数据含有多少组询问。
接下来有 T 行,每个询问各占 1 行,包含 1 个正整数,代表该询问的 S 值。
输出描述:
对于每个询问,请输出答案除以 2000000000000000003(共有17个零) 的余数。
示例1
输入
10
1
2
3
4
5
6
7
8
9
100
输出
1
2
3
4
6
9
12
18
27
7412080755407364
备注:
1 ≤ T ≤ 100
1 ≤ S ≤ 2000

思路:

找规律可知,当n%3==0 直接所有3相乘。

                        n%3==1 n/3 -1个3相乘,然后*4;

                        n%3==2  n/3 个3相乘,然后*2;

代码:

不知道为什么c++版一直wa,java版过了,可能是写的有问题。

import java.math.BigInteger;
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
    // write your code here
        // 7412080755407364
        Scanner in = new Scanner(System.in);
        int n;
        BigInteger x;
        BigInteger res;
        n = in.nextInt();
        for (int ca = 1; ca <= n; ca ++) {
            x = in.nextBigInteger();
            if (x.compareTo(new BigInteger("2")) <= 0) { //特判
                System.out.println(x);
                continue;
            }
            BigInteger pos = x.mod(new BigInteger("3"));
            if (pos.compareTo(new BigInteger("0")) == 0) {
                BigInteger cnt = x.divide(new BigInteger("3"));
                res = new BigInteger("1");
                for (int i = 0; i < Integer.valueOf(cnt.toString()); i ++) {
                    res = res.multiply(new BigInteger("3"));
                    res = res.mod(new BigInteger("2000000000000000003"));
                }
            } else if (pos.compareTo(new BigInteger("1")) == 0){
                BigInteger cnt = x.divide(new BigInteger("3"));
                res = new BigInteger("1");
                for (int i = 0; i < Integer.valueOf(cnt.toString()) - 1; i ++) {
                    res = res.multiply(new BigInteger("3"));
                    res.mod(new BigInteger("2000000000000000003"));
                }
                res = res.multiply(new BigInteger("4"));
                res = res.mod(new BigInteger("2000000000000000003"));
            } else {
                BigInteger cnt = x.divide(new BigInteger("3"));
                res = new BigInteger("1");
                for (int i = 0; i < Integer.valueOf(cnt.toString()); i ++) {
                    res = res.multiply(new BigInteger("3"));
                    res = res.mod(new BigInteger("2000000000000000003"));
                }
                res = res.multiply(new BigInteger("2"));
                res = res.mod(new BigInteger("2000000000000000003"));
            }
            System.out.println(res);
        }
    }
}


B

题目描述 
为了让所有选手都感到开心,Nowcoder练习赛总会包含一些非常基本的问题。 比如说:
按顺时针或逆时针方向给你一个简单的多边形的顶点坐标,请回答此多边形是顺时针还是逆时针。
输入描述:
输入包含N + 1行。
第一行包含一个整数N,表示简单多边形的顶点数。
在下面的N行中,第i行包含两个整数xi,yi,表示简单多边形中的第i个顶点的坐标。
输出描述:
如果简单多边形按顺时针顺序给出,则在一行中输出“clockwise”(不带引号)。 否则,打印"counterclockwise''(不带引号)。
示例1
输入
3
0 0
1 0
0 1
输出
counterclockwise
示例2
输入
3
0 0
0 1
1 0
输出
clockwise
备注:
3≤N≤30
-1000≤xi,yi≤1000
数据保证,这个简单多边形的面积不为零。

思路:

根据叉积求出面积。为正,则是counterclockwise,否则clockwise。

代码:

#include<iostream>
#include<string.h>
#include<string>
#include<vector>
#include<iomanip>
#include<math.h>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<time.h>
#include<queue>
#include<stack>
#include<set>
#define PI acos(-1.0)
#define ll long long
using namespace std;
struct node
{
    int x,y;
}a[10005];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d%d",&a[i].x,&a[i].y);
    int x1,y1,x2,y2;
    int ans=0;
    for(int i=2;i<=(n-1);i++)
    {
        x1=a[i].x-a[1].x;
        y1=a[i].y-a[1].y;

        x2=a[i+1].x-a[1].x;
        y2=a[i+1].y-a[1].y;

        ans+=(x1*y2-x2*y1);
    }
    if(ans>0) cout<<"counterclockwise"<<endl;
    else cout<<"clockwise"<<endl;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值