Codeforces Round #525 (Div. 2) A(暴力)B(暴力) C(思维)

A. Ehab and another construction problem(暴力)

题目链接:https://codeforces.com/contest/1088/problem/A

题目大意:给一个n,从[1,n]中选择两个数,符合a*b>n&&a/b<n&&b可以被a整除。

如果能选择,随便输出一对符合要求的数,不能就输出-1

题解:日常水题,n属于[1,100]直接暴力。

AC:

int main()
{
	std::ios::sync_with_stdio(false);
	int x;
	while(cin>>x)
	{
		int a=-1,b;
		for(int i=1;i<=x;++i)
		{//b
			for(int j=1;j*i<=x&&j<x;++j)
			{//a=b*j
				if(i*j*i>x)
				{
					a=i*j;
					b=i;
				}
			}
		}
		if(a==-1)
			cout<<-1<<endl;
		else
			cout<<a<<" "<<b<<endl;
	}
}

B. Ehab and subtraction(暴力)

题目链接:https://codeforces.com/contest/1088/problem/B

题目大意:给出一个数组,从这个数组中每次选择一个最小的元素,打印他,然后这个数组中所有的元素都减去这个数(0的话不减)。打印m次

思路:得到数组之后,从小到大排序,然后遍历这个数组,设置一个中间变量,每次+减去的值,在后面的时候再减去即可:

AC:
 

ll arr[MAXN];

int main()
{
	std::ios::sync_with_stdio(false);
	int n,k;
	while(cin>>n>>k)
	{
		clean(arr,0);
		for(int i=1;i<=n;++i)
			cin>>arr[i];
		sort(arr+1,arr+1+n);
		ll res=0;
		for(int i=1;i<=k;++i)
		{
			//cout<<res<<endl;
			if(i>n)
				cout<<"0 ";
			else if(arr[i]-res<=0)
			{
				k++;
				continue;
			}
			else
			{
				cout<<arr[i]-res<<" ";
				res+=(arr[i]-res);
			}
		}
		cout<<endl;
	}
}

C. Ehab and a 2-operation task(思维)

题目链接:https://codeforces.com/contest/1088/problem/C

题目大意:给你一个n个元素的数组,经过k([0,n])次操作后,使得这个数组种的元素值严格递增,每次操作可以选择两个:

操作1:x位置元素之前的所有元素都+一个数;操作2:x之前的所有元素都对一个数取模

思路:因为可以操作n次,所以我的想法是直接暴力,遍历一遍之后,每个数都+一个数,然后对每个数取模,取模剩下的值为1,2,3,。。。即可;

AC:

int arr[MAXN];

int main()
{
	std::ios::sync_with_stdio(false);
	int n;
	while(cin>>n)
	{
		clean(arr,0);
		for(int i=1;i<=n;++i)
		{
			cin>>arr[i];
			arr[i]+=1e5;
		}
		cout<<n+1<<endl<<"1 "<<n<<" 100000"<<endl;
		for(int i=1;i<=n;++i)
			cout<<"2 "<<i<<" "<<arr[i]-i<<endl;
	}
}

猜你喜欢

转载自blog.csdn.net/qq_40482358/article/details/86651936