牛客暑假四 N Particle Arts 【__int128的范围】【__int128特定的读入读出模板】【数据范围总结】

首先

__int128 太香了,最高39位

其次

明白

__int128 怎么写:

先写两个短横,后面才跟着一个int 

 __int128 的输入输出模板:

输出:

void print(__int128 x)

{

    if(x < 10) {

        cout << (char)(x + '0');

        return;

    }

    print(x / 10);

    cout << (char)('0' + (x % 10));

}

 

输入:

inline __int128 read() {

    __int128 x = 0, f = 1;

    char ch = getchar();

    while (ch < '0' || ch>'9') {

        if (ch == '-')f = -1;

        ch = getchar();

    }

    while (ch >= '0' && ch <= '9') {

        x = x * 10 + ch - '0';

        ch = getchar();

    }

    return x * f;

}

 

q:如何利用上述两个输入输出函数呢? 

 ans:

       s是__int128 类型的 

 

 

 

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

下面是各种数据类型

long long:最多19位

__int64:最多19位

unsigned long long:最多20位

unsigned __int64: 最多20位

__int128:最多39位 (前两者的两倍,太香了

 而__int64与__int128类型的输出是啥呢?

scanf("%I64d",&a); //注意此处是大写 i,不是l
printf("%I64d",a);

scanf("%I128d",&a); //注意此处是大写 i,不是l
printf("%I128d",a);

 链接:登录—专业IT笔试面试备考平台_牛客网
来源:牛客网
 

题目描述

(PDF statement: 百度网盘-链接不存在)

In a confined NIO space, there are nnn NIO particles, the iii-th of which has aia_iai​ joule energy. The NIO particles are very special as they keep colliding with each other randomly. When one particle carrying energy aaa joule collides with another particle carrying energy bbb joule, they will be annihilated and produce two new particles carrying the energy of a AND ba\ \texttt{AND}\ ba AND b and a OR ba\ \texttt{OR}\ ba OR b respectively. Here AND\texttt{AND}AND and OR\texttt{OR}OR mean bitwise AND and OR operation respectively.


The variance of the energy of these particles is obviously not decreasing, but unfortunately, the space here is too small for the author to write down his proof. After enough time the variance of the energy of these particles converges to a stable value. Can you find this value?

The variance of nnn numbers is defined as follows.

σ2=1n∑i=1n(xi−μ)2where μ=1n∑i=1nxi\begin{aligned} \sigma^2 &= \frac{1}{n}\sum\limits_{i=1}^{n}(x_i - \mu)^{2} \\ \text{where}\ \mu &= \frac{1}{n}\sum\limits_{i=1}^{n}x_i \\ \end{aligned}σ2where μ​=n1​i=1∑n​(xi​−μ)2=n1​i=1∑n​xi​​

输入描述:

The first line contains an integer nnn (2≤n≤1052\le n\le 10^52≤n≤105), indicating the number of particles.

The second line contains nnn integers a1,a2,…,ana_1,a_2,\ldots, a_na1​,a2​,…,an​ (0≤ai<2150\le a_i < 2^{15}0≤ai​<215), indicating the enegery of the particles.

输出描述:

Output a irreducible fraction ab\dfrac{a}{b}ba​ (b>0b > 0b>0) in the form of a/b\texttt{a/b}a/b that represents the answer. You should ensure that gcd⁡(a,b)=1\gcd(a,b) = 1gcd(a,b)=1 or when a=0a=0a=0, bbb should be 111.

示例1

输入

复制5 1 2 3 4 5

5
1 2 3 4 5

输出

复制54/5

54/5

备注:

Warm tip: Please note the use of data types.
#include <bits/stdc++.h>
using namespace std;
typedef __int128 LL;
const int N=1e5+10;
LL a[N];
LL cnt[20];
LL xin[N];

inline __int128 read() {
	__int128 x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') {
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') {
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}

void print(__int128 x)
{
    if(x < 10) {
        cout << (char)(x + '0');
        return;
    }
    print(x / 10);
    cout << (char)('0' + (x % 10));
}

LL gcd(LL a,LL b)
{
 return b>0 ? gcd(b,a%b):a;
}
int main()
{
    LL n;
    n = read();


    for(int i=1;i<=n;i++)
        a[i] = read();

    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<15;j++)
        {
            if(a[i]>>j&1)
            {
                cnt[j]++;
            }
        }
    }


    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<15;j++)
        {
            if(cnt[j])
            {
                xin[i]+=1<<j;
                cnt[j]--;
            }
        }
    }

    LL sum=0;
    for(int i=1;i<=n;i++)
    {
        sum+=xin[i];
    }

    LL zi=0;
    for(int i=1;i<=n;i++)
    {
        LL t=(LL)(n*xin[i]-sum)*(n*xin[i]-sum);
        zi+=t;
    }
    LL mu=n*n*n;

    LL d=gcd(zi,mu);
    zi=zi/d;
    mu=mu/d;

    if(zi==0) mu=1;
    print(zi);
    putchar('/');
    print(mu);
    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值