10-28

Dubious Cyrpto

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
题目的大致意思为:已知正整数 l, r, m 求任意一组 a, b, c 使得存在正整数 n 满足 n * a + b - c = m 且a, b, c 均在 [l, r] 这个范围之内,让你构造一个a,b,c使得na+b-c==m。
题解: 这道题它确保了至少有一个a,b,c能够使得n
a+b-c=m,所以我只要让c=l,或者c=r,然后去遍历一遍l到r之间的值就行了。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
int main()
{
    int t;
    cin >> t;
    while(t--){
        LL l, r;
        LL m;
        LL min1 = INF;
        LL min2 = -INF;
        LL minl=-1;
        LL minr=-1;
        cin >> l >> r >> m;
        for (int i = (int)l;i<=(int)r;i++){
            if(m/i!=0){
                int n1 = m - m / i * i;
                int n2 = m - (m / i + 1) * i;
                if (min1 > n1)
                {
                    min1 = n1;
                    minl = i;
                }
                if(min2 < n2){
                    min2 = n2;
                    minr = i;
                }
            }
            else {
                int n2 = m - (m / i + 1) * i;
                if(min2 < n2){
                   min2 = n2;
                   minr = i;
                }
            }
        }
        if(abs(min2) < min1)
            cout << minr << " " << r + min2 << " " << r << endl;
        else
            cout << minl << " " << l + min1 << " " << l  << endl;
    }
}

Xenia and Bit Operations
在这里插入图片描述
在这里插入图片描述
**题目的大致意思就是:**给你2 ^ n个数a[n^2],让你去构建一个二叉树,从底层开始进行或,异或,或,异或的操作,给你m次询问,给你两个数p,b。让你将将a[p]的值改为b,让你去计算修改以后根节点的值。
思路: 每个数即为线段数的节点,每更改一次,其父节点的值也跟着更改,最终输出根节点的值即可。

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6;
int ah[maxn];int court;
struct Tree{
	int l,r;int val;int h;
}tree[maxn<<2];
void Pushup(int i){
	tree[i].h=tree[i<<1].h*(-1);
	if(tree[i].h==-1)tree[i].val=tree[i<<1].val|tree[(i<<1)|1].val;
	else tree[i].val=tree[i<<1].val^tree[(i<<1)|1].val;
}
void build(int i,int l,int r){
	tree[i].l=l;tree[i].r=r;
	if(l==r){
		tree[i].h=1;
		tree[i].val =ah[l];
		return;
	}
	int mid=(l+r)/2;
	build(i<<1,l,mid);
	build((i<<1)|1,mid+1,r);
	Pushup(i);
}
void update(int i,int k,int v){
	if(tree[i].l==k&&tree[i].r==k){
		tree[i].val=v;
		return;
	}
	int mid=(tree[i].l+tree[i].r)/2;
	if(k<=mid)update(i<<1,k,v);
	else update((i<<1)|1,k,v);
	Pushup(i);
}
int main(){
	int n;int m;int c=1;int b,a;
	scanf("%d%d",&n,&m);
	court=n;
	for(int i=1;i<=n;i++){
		c=c*2;
	}
	for(int i=1;i<=c;i++){
		scanf("%d",&ah[i]);
	}
	build(1,1,c);
	for(int i=1;i<=m;i++){
		scanf("%d%d",&a,&b);
		update(1,a,b);
		printf("%d\n",tree[1].val);
	}
}

Big Vova
Alexander is a well-known programmer. Today he decided to finally go out and play football, but with the first hit he left a dent on the new Rolls-Royce of the wealthy businessman Big Vova. Vladimir has recently opened a store on the popular online marketplace “Zmey-Gorynych”, and offers Alex a job: if he shows his programming skills by solving a task, he’ll work as a cybersecurity specialist. Otherwise, he’ll be delivering some doubtful products for the next two years.

You’re given n positive integers a1,a2,…,an. Using each of them exactly at once, you’re to make such sequence b1,b2,…,bn that sequence c1,c2,…,cn is lexicographically maximal, where ci=GCD(b1,…,bi) - the greatest common divisor of the first i elements of b.

Alexander is really afraid of the conditions of this simple task, so he asks you to solve it.

A sequence a is lexicographically smaller than a sequence b if and only if one of the following holds:

a is a prefix of b, but a≠b;
in the first position where a and b differ, the sequence a has a smaller element than the corresponding element in b.

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤10^3). Description of the test cases follows.

The first line of each test case contains a single integer n (1≤n≤10^3) — the length of the sequence a.

The second line of each test case contains n integers a1,…,an (1≤ai≤10^3) — the sequence a.

It is guaranteed that the sum of n over all test cases does not exceed 10^3.

Output

For each test case output the answer in a single line — the desired sequence b. If there are multiple answers, print any.

Example

input
7
2
2 5
4
1 8 2 3
3
3 8 9
5
64 25 75 100 50
1
42
6
96 128 88 80 52 7
5
2 4 8 16 17

output

5 2
8 2 1 3
9 3 8
100 50 25 75 64
42
128 96 80 88 52 7
17 2 4 8 16

Note

In the first test case of the example, there are only two possible permutations b — [2,5] and [5,2]: for the first one c=[2,1], for the second one c=[5,1].

In the third test case of the example, number 9 should be the first in b, and GCD(9,3)=3, GCD(9,8)=1, so the second number of b should be 3.

In the seventh test case of the example, first four numbers pairwise have a common divisor (a power of two), but none of them can be the first in the optimal permutation b.

这道题题目意思有点难理解,读了半天,大致意思是给你有n个数序列a,让你去构造一个序列b,使得序列c的最大,c的第i个元素等于gcd(b1,b2,……,bi)。
序列大小判断跟字符串的大小判断差不多,这里就不说了。
我的思路是b的第一个元素一定是a中最大的元素,b的第一个元素确认,GCD=b1,然后去遍历a数组去找与GCD的最小公因数最大,最大的就是b2,此时GCD=gcd(b1,b2),这样下去,如果GCD=1,那么说明剩下的数这么输出都没事,就去遍历一遍将为加入的数输出就可以了。
代码如下:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int maxn=1e3+10;
int a[maxn];
int b[maxn];
bool com(int a,int b){
	return a>b;
}
int gcd(int a,int b){
	return b==0?a:gcd(b,a%b);
}
int main(){
	int t;
	cin>>t;
	while(t--){
		memset(b,0,sizeof b);
		int n;
		cin>>n;
		int cnt=n;
		for(int i=1;i<=n;i++){
			cin>>a[i];
		}
		sort(a+1,a+1+n,com);
		b[1]=1;
		cout<<a[1]<<" ";
		int max1=1;
		int gcd1=a[1];
		int i1=1;
		cnt=cnt-1;
		for(int i=1;i<n;i++){
			max1=1;
			for(int j=1;j<=n;j++){
				if(gcd(gcd1,a[j])>max1&&!b[j]){
					max1=gcd(gcd1,a[j]);
					i1=j;
				}
			}
			b[i1]=1;
			gcd1=max1;
			if(max1==1){
				for(int j=1;j<=n;j++){
				    if(!b[j]){
					    printf("%d",a[j]);
				         if(cnt==1)cout<<endl;
			             else{cnt--;cout<<" ";} 
				}
				}
				break;
			}
			else {printf("%d",a[i1]);
			if(cnt==1)cout<<endl;
			else {cnt--;cout<<" ";} 
			}
		}
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ava实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),可运行高分资源 Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现
C语言是一种广泛使用的编程语言,它具有高效、灵活、可移植性强等特点,被广泛应用于操作系统、嵌入式系统、数据库、编译器等领域的开发。C语言的基本语法包括变量、数据类型、运算符、控制结构(如if语句、循环语句等)、函数、指针等。下面详细介绍C语言的基本概念和语法。 1. 变量和数据类型 在C语言中,变量用于存储数据,数据类型用于定义变量的类型和范围。C语言支持多种数据类型,包括基本数据类型(如int、float、char等)和复合数据类型(如结构体、联合等)。 2. 运算符 C语言中常用的运算符包括算术运算符(如+、、、/等)、关系运算符(如==、!=、、=、<、<=等)、逻辑运算符(如&&、||、!等)。此外,还有位运算符(如&、|、^等)和指针运算符(如、等)。 3. 控制结构 C语言中常用的控制结构包括if语句、循环语句(如for、while等)和switch语句。通过这些控制结构,可以实现程序的分支、循环和多路选择等功能。 4. 函数 函数是C语言中用于封装代码的单元,可以实现代码的复用和模块化。C语言中定义函数使用关键字“void”或返回值类型(如int、float等),并通过“{”和“}”括起来的代码块来实现函数的功能。 5. 指针 指针是C语言中用于存储变量地址的变量。通过指针,可以实现对内存的间接访问和修改。C语言中定义指针使用星号()符号,指向数组、字符串和结构体等数据结构时,还需要注意数组名和字符串常量的特殊性质。 6. 数组和字符串 数组是C语言中用于存储同类型数据的结构,可以通过索引访问和修改数组中的元素。字符串是C语言中用于存储文本数据的特殊类型,通常以字符串常量的形式出现,用双引号("...")括起来,末尾自动添加'\0'字符。 7. 结构体和联合 结构体和联合是C语言中用于存储不同类型数据的复合数据类型。结构体由多个成员组成,每个成员可以是不同的数据类型;联合由多个变量组成,它们共用同一块内存空间。通过结构体和联合,可以实现数据的封装和抽象。 8. 文件操作 C语言中通过文件操作函数(如fopen、fclose、fread、fwrite等)实现对文件的读写操作。文件操作函数通常返回文件指针,用于表示打开的文件。通过文件指针,可以进行文件的定位、读写等操作。 总之,C语言是一种功能强大、灵活高效的编程语言,广泛应用于各种领域。掌握C语言的基本语法和数据结构,可以为编程学习和实践打下坚实的基础。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值