The Crime-solving Plan of Groundhog(大整数乘法)

2024-04-16 00:18

本文主要是介绍The Crime-solving Plan of Groundhog(大整数乘法),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

题意:
0~9每个数字都给你一些,要求配成两个没有前导0的数字,使得乘积最小。

思路:
第二个数字为一个的时候乘积最小,所以直接模拟乘法。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <vector>using namespace std;
typedef long long ll;
const int maxn = 2e6 + 7;
const int mod = 998244353;int vis[maxn];
struct Node {int id,x;
}a[maxn];int cmp(Node a,Node b) {if(a.x == b.x) return a.id < b.id;return a.x < b.x;
}int main() {int n,m;scanf("%d%d",&n,&m);int cnt = 0;for(int i = 1;i <= n;i++) {int amt;scanf("%d",&amt);for(int j = 1;j <= amt;j++) {int x;scanf("%d",&x);a[++cnt] = {i,x};}}sort(a + 1,a + 1 + cnt,cmp);int l = 1,now = 0;int ans = 1e9;for(int i = 1;i <= cnt;i++) {vis[a[i].id]++;if(vis[a[i].id] == 1) {now++;if(now >= m) {ans = min(ans,a[i].x - a[l].x);}}while(now >= m) {vis[a[l].id]--;if(vis[a[l].id] == 0) {now--;}l++;if(now >= m)ans = min(ans,a[i].x - a[l].x);}}printf("%d\n",ans);return 0;
}

这篇关于The Crime-solving Plan of Groundhog(大整数乘法)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/907316

相关文章

PTA求一批整数中出现最多的个位数字

作者 徐镜春 单位 浙江大学 给定一批整数,分析每个整数的每一位数字,求出现次数最多的个位数字。例如给定3个整数1234、2345、3456,其中出现最多次数的数字是3和4,均出现了3次。 输入格式: 输入在第1行中给出正整数N(≤1000),在第二行中给出N个不超过整型范围的非负整数,数字间以空格分隔。 输出格式: 在一行中按格式“M: n1 n2 ...”输出,其中M是最大次数,n

整数Hash散列总结

方法:    step1  :线性探测  step2 散列   当 h(k)位置已经存储有元素的时候,依次探查(h(k)+i) mod S, i=1,2,3…,直到找到空的存储单元为止。其中,S为 数组长度。 HDU 1496   a*x1^2+b*x2^2+c*x3^2+d*x4^2=0 。 x在 [-100,100] 解的个数  const int MaxN = 3000

hdu 6198 dfs枚举找规律+矩阵乘法

number number number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description We define a sequence  F : ⋅   F0=0,F1=1 ; ⋅   Fn=Fn

单精度浮点数按存储格式转为整数的程序

///#include<cstdio>//-----------------union int_char{unsigned char ch[4];float i;};void out_put(union int_char x)//x86是小端对其模式,即最数据的最低位存储在地址的最低位上。{printf("单精度浮点数值为:%f\n",x.i,x.i);printf("存储位置从左到右

高精度加法,乘法,阶乘

#include <iostream>#include <map>#include <string>#include <algorithm>using namespace std;const int Max = 50000;string str1,str2;/***********乘法***********/void chenfa(){cin >> str1>>str2;int a

Study Plan For Algorithms - Part24

1. 包含min函数的栈 定义栈的数据结构,要求在该类型中实现一个 min 函数,能够获取栈的最小元素。在该栈中,调用 min、push 以及 pop 函数的时间复杂度均为 O (1)。 方法: class MinStack:def __init__(self):self.stack = []self.min_stack = [float('inf')]def push(self, x):sel

用异或交换两个整数的陷阱

前面我们谈到了,可用通过异或运算交换两个数,而不需要任何的中间变量。 如下面: void exchange(int &a, int &b) {     a ^= b;     b ^= a;     a ^= b; } 然而,这里面却存在着一个非常隐蔽的陷阱。 通常我们在对数组进行操作的时候,会交换数组中的两个元素,如exchang(&a[i], &b[j]),

Java中等题-整数替换(力扣)

给定一个正整数 n ,你可以做如下操作: 如果 n 是偶数,则用 n / 2替换 n 。如果 n 是奇数,则可以用 n + 1或n - 1替换 n 。 返回 n 变为 1 所需的 最小替换次数 。 示例 1: 输入:n = 8输出:3解释:8 -> 4 -> 2 -> 1 示例 2: 输入:n = 7输出:4解释:7 -> 8 -> 4 -> 2 -> 1或 7 ->

43. 1 ~ n 整数中 1 出现的次数【难】

comments: true difficulty: 中等 edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9843.%201%EF%BD%9En%E6%95%B4%E6%95%B0%E4%B8%AD1%E5%87%BA%E7%8E%B0%E7%9A%84%E6%AC%A1%

乘法问题c++

题目描述 小 A 最近刚刚学习了乘法,为了帮助他练习,我们给他若干个正整数,并要求他将这些数乘起来。 对于大部分题目,小 A 可以精准地算出答案,不过,如果这些数的乘积超过 ,小 A 就不会做了。 请你写一个程序,告诉我们小 A 会如何作答。 输入 第一行一个整数 n,表示正整数的个数。 接下来 n行,每行一个整数a 。小 A 需要将所有的 a乘起来。 保证n<=50,a<=100. 输出