CF Round #528 Div. 2

版权声明:版权归Ordinarv所有 https://blog.csdn.net/ordinarv/article/details/85254408

A

B - Div Times Mod
题意:给出n,k 求 一个 使等式成立的最小正整数x
思路 :  令(x%k)   = a 则 原式变为 (x-a)/k * a = n   这里 a∈ (1,k)并且为n的因子
解出x来得到 x= n*k / a + a   求最小值即可。即 在a的定义域内找一个最靠近   sqrt (n*k)就是最小值
 

#include<bits/stdc++.h>
using namespace std;
int n,k,x,a,b,c,ans,ttt=0x3f3f3f3f,ad;
int main()
{
    scanf("%d%d",&n,&k);
    c=sqrt(k*n);
    for(int i=1; i<k; i++)
    {
        if(n%i==0)
        {
            if(abs(i-c)<ttt)
            {
                ttt=abs(i-c);
                ad=i;
            }
        }
    }
    ans=n*k/ad+ad;
    printf("%d\n",ans);
    return 0;
}

C 模拟

#include<bits/stdc++.h>
using namespace std;
struct unt {
	int x,y;
} coo[5];
bool cmp(unt a,unt b) {
	if(a.x == b.x) return a.y < b.y;
	return a.x < b.x;
}
int main() {
	int n = 3;
	int x,y,minx=1000,miny=1000,maxx=0,maxy=0;
	for(int i=0; i<3; i++) {
		cin>>x>>y;
		maxx = max(maxx,x);
		minx = min(minx,x);
		maxy = max(maxy,y);
		miny = min(miny,y);
		coo[i].x = x;
		coo[i].y = y;
	}
	sort(coo,coo+n,cmp);
	int ans = maxx - minx + (maxy - miny) + 1;
	cout<<ans<<endl;

	int tem = min(coo[0].y,min(coo[1].y,coo[2].y));
	while(tem<=maxy) {
		cout<<coo[1].x<<' '<<tem<<endl;
		tem++;
	}


	tem = coo[0].x;
	while(tem<coo[1].x) {
		cout<<tem<<' '<<coo[0].y<<endl;
		tem++;
	}

	tem = coo[1].x+1;
	while(tem<=coo[2].x) {
		cout<<tem<<' '<<coo[2].y<<endl;
		tem++;
	}

	return 0;
}

猜你喜欢

转载自blog.csdn.net/ordinarv/article/details/85254408
今日推荐