zoukankan      html  css  js  c++  java
  • 北京邀请赛 B. Beautiful Garden

    题意:给你坐标和n个点,求最少移动的点使得n个点成等差数列

    思路:既然要成等差数列,那么最起码有两个点是不动的,然后枚举这两个点中间的点的个数,近期水的要死,看了队友的代码做的

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cstdlib>
    #include <cmath>
    using namespace std;
    const double eps = 1e-9;
    const int INF = 0x3f3f3f3f;
    
    int n;
    double x[45];
    
    int main() {
    	int cas = 1,t;
    	scanf("%d", &t);
    	while (t--) {
    		scanf("%d", &n);
    		for (int i = 0; i < n; i++) 
    			scanf("%lf", &x[i]);
    		sort(x, x+n);
    		printf("Case #%d: ", cas++);
    		if (n == 1){
    			printf("0
    ");
    			continue;
    		}
    		int ans = INF;
    		for (int i = 0; i < n; i++)
    			for (int j = i+1; j < n; j++) 
    				for (int k = 1; k < n; k++) {
    					int count = 0;
    					double d = (x[j]-x[i])/k;
    					double cur = x[i]-d;
    					int cnt = 0;
    					for (int l = 0; l < n; l++) {
    						cur += d;
    						while (x[cnt] < cur && cnt < n)
    							cnt++;
    						if (cnt == n)
    							break;
    						if (fabs(cur-x[cnt]) < eps) {
    							count++;
    							cnt++;	
    						}
    					}
    					ans = min(ans, n-count);
    				}
    		printf("%d
    ", ans);
    	}
    	return 0;
    }



查看全文
  • 相关阅读:
    RapidJavaEE 项目 开发流程说明
    [转]Ext自定义vtype动态验证
    博客园cnblogs chrome右键插件 开发
    extjs 2.0 回车切换表单,支持chrome,firefox,ie
    简单备份策略
    搜狗室验室 Web开发相关技术报告下载
    <转>记录一些BCB6的使用心得
    (转)远程桌面3389多用户登陆补丁及端口修改(XP+WIN7)
    <转>Java调用C/C++编写的第三方dll动态链接库(非native API) JNI
    清理SVN目录中.SVN
  • 原文地址:https://www.cnblogs.com/ldxsuanfa/p/10894130.html
  • Copyright © 2011-2022 走看看