k-Multiple Free Set(set 二分)

这篇博客介绍了CodeForces 274A - VirtualJudge问题的解决方案,即寻找数组中没有k倍数的最大元素个数。两种解法分别是利用集合(set)和二分查找。第一种方法通过集合存储k倍数,避免重复;第二种方法通过二分查找判断每个元素的k倍数是否已存在,减少计数。这两种方法都有效地解决了问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

k-Multiple Free Set - CodeForces 274A - Virtual Judge (csgrandeur.cn)


题意:给你一个数组和一个值k,定义一个集合表示的是一组整数,其中没有一个整数等于另一个整数乘以k,求这个整数的最大数量。


思路:集合里如果有x,一定不能有k倍的x。


解法1:set

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+10;
set<int> st;
int a[N],n,k;

signed main()
{
	cin>>n>>k;
	
	for(int i=1;i<=n;i++) cin>>a[i];
	
	sort(a+1,a+n+1);
	int res=0;
	
	for(int i=1;i<=n;i++)
	{
		int x=a[i];
		if(st.count(x)==0)
		{
			res++;
			st.insert(x*k);
		}
	}
	
	cout<<res<<endl;
	
	return 0;
}

 

解法2:二分找a[i]的k倍,找到到了res--

​
​
#include<bits/stdc++.h>
#define int long long
#define x first
#define y second
#define mak make_pair
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define debug(a) cout<<a<<'\n'
#define endl '\n'
#define umap unordered_map
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=1e5+10,M=1,inf=0x3f3f3f3f,mod=1e9+7;
int a[N],n,k;
bool st[N];//某个数的k倍有没有被找到

signed main()
{
    cin>>n>>k;
    
    for(int i=1;i<=n;i++) cin>>a[i];
    
    sort(a+1,a+n+1);
    
    int res=n;
    
    for(int i=1;i<=n;i++)
    {
    	if(st[i]) continue;
    	int l=i,r=n;
    	
    	while(l<r)
    	{
    		int mid=l+r+1>>1;
    		
    		if(a[mid]==a[i]*k)
    		{
    			res--;
    			st[mid]=true;
    			break;
			}
			
			if(a[mid]<a[i]*k) l=mid;
			else r=mid-1;
		}
    	
    	
	}
    
    cout<<res<<endl;
    
	return 0;
}


​

​

END


### YOLOv8 Anchor-Free Mechanism Implementation and Working Principle In the evolution from earlier versions to YOLOv8, significant changes have been introduced including moving towards an anchor-free mechanism which simplifies object detection models by eliminating predefined anchor boxes. This approach directly regresses bounding box coordinates relative to specific points within feature maps rather than relying on a set of pre-defined anchors. The core idea behind this transformation lies in reducing model complexity while improving performance efficiency. In traditional methods like those used before YOLOv5, multiple scales were covered through various sizes and aspect ratios defined as anchor boxes during training; however, these required careful tuning depending upon dataset characteristics[^1]. With the adoption of an anchor-free strategy in YOLOv8: - **Direct Regression**: Instead of predicting offsets against fixed-size templates (anchors), predictions are made concerning key locations identified across different levels of convolutional features. - **Center Points Identification**: For each ground truth bounding box, only one point—the center—is selected for positive sample assignment instead of all possible anchor matches at that location. - **Loss Function Adjustment**: Loss functions adapt accordingly so they can effectively train without needing IoU calculations between predicted and actual bounding boxes since there's no concept of 'matching' here anymore. This shift not only streamlines configuration but also potentially enhances generalization capabilities over diverse datasets because it reduces dependency on manually specified parameters such as anchor dimensions. For implementing this change technically within codebase structures similar to what might be seen when using tools designed around Go routines management or other concurrent processing utilities mentioned previously [^2], developers would focus more heavily on ensuring efficient memory usage patterns alongside precise synchronization mechanisms among parallel tasks involved throughout both forward passes during inference time along backward propagation steps needed for optimization purposes. ```go // Example pseudo-code demonstrating how concurrency could play into optimizing certain aspects related to anchor-free implementations, func processImage(imageData []byte) { var wg sync.WaitGroup // Assume we spawn workers per region proposal task where applicable regions := divideIntoRegions(imageData) resultsChan := make(chan RegionResult) for _, r := range regions { wg.Add(1) go func(region ImageRegion){ defer wg.Done() result := analyzeRegionAnchorFree(region) resultsChan <- result }(r) } go func(){ wg.Wait() close(resultsChan) }() } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值