The input starts with one line containing exactly one integer t which is the number of test cases. (1 ≤ t ≤ 50)
For each test case, the first line contains four integers n, A, B, C. (2 ≤ n ≤ 107, A, B, C are randomly selected in unsigned 32 bits integer range)
No more than 5 cases have n greater than 2 x 106.
For each test case, output "Case #x: y" in one line (without quotes), where x is the test case number (starting from 1) and y is the maximum lcm.
Case #1: 68516050958 Case #2: 5751374352923604426
题意: 读题只读最后一句话系列。t组样例,t不超过50。每组样例四个数字n,a,b,c,n代表序列有n个数字,不超过5组样例n大于2e6,n<1e7。a,b,c在推出序列的过程中使用,数据范围unsigned int
按照题意中给出的代码,每运行一次得到的就是a[i],最后要求选出两个数字使其LCM最大,输出最大的LCM。
做法:丧心病狂,不是第一次遇见这样的解法了,也就是保留前100大,然后暴力求LCM即可。
注意******* 题目上说了a,b,c都是unsigned int类型的,不能开成unsigned long long类型的,不正常取舍答案会错误。
nth_element(a,a+k,a+n,cmp);可以得到前k小或者前k大,自定义排序方式
代码如下:
#include<stdio.h> #include<iostream> #include<algorithm> using namespace std; const int maxn = 10000007; int t; int n; unsigned int x , y , z; unsigned long long num[maxn]; unsigned long long gcd(unsigned long long a , unsigned long long b) { unsigned long long c; c = a%b; while( c ) { a = b; b = c; c = a%b; } return b; } unsigned int solve() { unsigned int tt; x ^= x<<16; x ^= x>>5; x ^= x<<1; tt = x; x = y; y = z; z = tt^x^y; return z; } bool cmp(unsigned long long a , unsigned long long b) { return a>b; } int main() { scanf("%d" , &t); for(int cas=1; cas<=t; cas++) { scanf("%d%u%u%u" , &n , &x , &y , &z); for(int i=0; i<n; i++) { num[i] = solve(); } int k = min(100 , n); ///取前100大 nth_element(num , num+k , num+n , cmp); unsigned long long ans; ans = 0; for(int i=0; i<k; i++) { // printf("%llu\n" , num[i]); for(int j=i+1; j<k; j++) { ans = max(ans , num[i]*num[j]/gcd(num[i],num[j])); // printf("%d..%d..%llu..%llu..%llu..%llu..\n" , i , j , num[i] , num[j] , num[i]*num[j]/gcd(num[i],num[j]) , ans); } } printf("Case #%d: %llu\n" , cas , ans); } return 0; } /* 337929 608269 1351708 64488027082 85984357633 405514 675854 1351708 1384776332 2769433858 0..1..405514..675854..137034129478..137034129478.. 0..2..405514..1351708..274068258956..274068258956.. 0..3..405514..1384776332..280773094747324..280773094747324.. 0..4..405514..2769433858..561522100746506..561522100746506.. 1..2..675854..1351708..1351708..561522100746506.. 1..3..675854..1384776332..467953311543764..561522100746506.. 1..4..675854..2769433858..935866475332366..935866475332366.. 2..3..1351708..1384776332..467953311543764..935866475332366.. 2..4..1351708..2769433858..1871732950664732..1871732950664732.. 3..4..1384776332..2769433858..1917523229798924428..1917523229798924428.. */
牛客网暑期ACM多校训练营(第六场)J Heritage of skywalkert
原文:https://www.cnblogs.com/Flower-Z/p/9643476.html