Happy Reversal

本文介绍了一个关于二进制数操作的问题,即通过执行NOT操作来最大化一组长度相同的二进制数之间的最大值与最小值之差。文章提供了完整的代码实现,并详细解释了输入输出的格式。

Happy Reversal
Time Limit: 1000msMemory Limit: 65536KB 64-bit integer IO format: %lld Java class name: Main
Submit Status PID: 34988
Elfness is studying in an operation “NOT”.
For a binary number A, if we do operation “NOT A”, after that, all digits of A will be reversed. (e.g. A=1001101, after operation “NOT A”, A will be 0110010).
Now Elfness has N binary numbers of length K, now he can do operations “NOT” for some of his numbers.
Let’s assume after his operations, the maximum number is M, the minimum number is P. He wants to know what’s the maximum M - P he can get. Can you help him?

Input
The first line of input is an integer T (T ≤ 60), indicating the number of cases.
For each case, the first line contains 2 integers N (1 ≤ N ≤ 10000) and K (1 ≤ K ≤ 60), the next N lines contains N binary numbers, one number per line, indicating the numbers that Elfness has. The length of each binary number is K.

Output
For each case, first output the case number as “Case #x: “, and x is the case number. Then you should output an integer, indicating the maximum result that Elfness can get.

Sample Input
2
5 6
100100
001100
010001
010001
111111
5 7
0001101
0001011
0010011
0111000
1001011
Sample Output
Case #1: 51
Case #2: 103


#include <stdio.h>
#include <string.h>
#include <limits.h>
#define INF 0x7fffffffffffffffl
int n, k;
char bin[10005][65];
long long val[50005], cnt;
void change(int x, int sign)
{
    long long ret, r;
    ret = 0;
    r = 1;
    if (sign == 1)
    {
        for (int i = k - 1; i >= 0; i--)
        {
            ret += r*(bin[x][i] - '0');
            r = r * 2;
        }
    }
    else
    {
        for (int i = k - 1; i >= 0; i--)
        {
            if (bin[x][i] == '0')
                ret += r;
            r = r * 2;
        }
    }
    val[cnt++] = ret;
    for(int i=0;i<2*n;i++)
    {
        printf("%d ",val[i]);
    }
}
int main()
{
    int t, CASE = 1;
    scanf("%d", &t);
    while (t--)
    {
        scanf("%d%d", &n, &k);
        cnt = 0;
        for (int i = 0; i < n; i++)
        {
            scanf("%s", bin[i]);
            change(i, 1);//这两个函数调用是把原二进制与not二进制存到一个数组中去
            change(i, -1);
        }
        long long max, min, s1, s2;//接下来就是如果一个数最大了,且这个数的not是最小的要选最大数减去第二小的数
        max = val[0];
        s1 = 0;
        for (int i = 1; i < 2 * n; i++)
            if (max < val[i])
            {
                max = val[i];
                s1 = i;
            }
            printf("%d ***** %d\n",s1,val[s1]);
        if (0 == s1 % 2) s2 = s1 + 1;
        else s2 = s1 - 1;
        min = INF;
        for (int i = 0; i < 2 * n; i++)
            if (i != s2&&min>val[i]) min = val[i];
        printf("Case #%d: %lld\n", CASE++, max - min);
    }
    return 0;
}
import pandas as pd import numpy as np from pyecharts.charts import Bar import pyecharts.options as opts path_marry = r"D:\迅雷下载\新建文件夹\数据集\数据可视化数据集\结婚离婚\结婚数据.csv" path_divorse = r"D:\迅雷下载\新建文件夹\数据集\数据可视化数据集\结婚离婚\离婚数据.csv" marry_data = pd.read_csv(path_marry) divorse_data = pd.read_csv(path_divorse) divorse_data = divorse_data.set_index(divorse_data["地区"]).drop(columns=["地区"]) show_data2 = marry_data["2019年"] show_data3 = divorse_data["2019年"] show_data4=pd.DataFrame() show_data4["结婚登记数"]=show_data2 show_data4["离婚登记数"]=show_data3 show_data4["结婚登记数占比"]=show_data4["结婚登记数"]/show_data4.sum(axis=1) show_data4["离婚登记数占比"]=1-show_data4["结婚登记数占比"] x_axis_data = show_data3.index.tolist() y_axis_data1 = show_data2.values.tolist() y_axis_data2 = show_data3.values.tolist() c = ( Bar(init_opts=opts.InitOpts(width="800px", height="700px")) .add_xaxis(x_axis_data) .add_yaxis( "2019年结婚登记数量(万对)" , y_axis_data1 ,stack="happy" ,itemstyle_opts={"color":"#006400"} ) .add_yaxis( "2019年离婚登记数量(万对)" , y_axis_data2 ,stack="happy" ) .reversal_axis() .set_series_opts(label_opts=opts.LabelOpts(position="right")) .set_global_opts( title_opts=opts.TitleOpts(title="全国各省2019年结婚登记数量(万对)") ,legend_opts=opts.LegendOpts( pos_left="40%" ,orient="vertical" ) ) ) c.render_notebook()请对这段代码修改,转为显示2个y变量的占比(总和为1)
06-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值