BestCoder Round #50 (div.2)

1001.

题解:水过~~用数组统计一下就好了。。

#include<iostream>
#include<cstdio>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
int main()
{
    int n,a[1002],b[10002];
    while(cin>>n){
        for(int i=0;i<n;i++)
            cin>>a[i];

    memset(b,0,sizeof(b));
    for(int i=0;i<n;i++){
          b[a[i]]++;
    }
    int maxn=0,id=0;
    for(int i=0;i<n;i++)
        if(b[a[i]]>maxn)
        {
             maxn=b[a[i]];
             id=a[i];
        }

      if(maxn>n-maxn)cout<<id<<endl;
      else cout<<"-1"<<endl;
    }
    return 0;
}
1002.

题解:写了好久没做出来,就去写1003了,我没主要到是整数点,整数点是出不来正三,五,六变形的,可以在网格中试试,确实画不出来。做一只需验证正方形就行了,枚举所有边,四条边相等,对角线相等就可以了。

#include <iostream>
#include <algorithm>
#include <cstdio>
#define LL long long
#define INF 0x7fffffff
using namespace std;

struct node {
    int x, y;
}a[55];

int n;

int fun(node a, node b) {
    return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}

int main() {
    while(scanf("%d", &n) != EOF) {
        for(int i = 0; i < n; i ++) {
            scanf("%d %d", &a[i].x, &a[i].y);
        }

        int ans = 0;
        for(int i = 0; i < n; i ++) {
            for(int j = i + 1; j < n; j ++) {
                for(int k = j + 1; k < n; k ++) {
                    for(int l = k + 1; l < n; l ++) {
                        int x[6];
                        x[0] = fun(a[i], a[j]);
                        x[1] = fun(a[j], a[k]);
                        x[2] = fun(a[k], a[l]);
                        x[3] = fun(a[l], a[i]);
                        x[4] = fun(a[i], a[k]);
                        x[5] = fun(a[j], a[l]);
                        sort(x, x + 6);
                        if((x[0] == x[1]) && (x[0] == x[2]) && (x[0] == x[3]) && (x[4] == x[5])) {
                            ans ++;
                        }
                    }
                }
            }
        }
        printf("%d\n", ans);

    }
    return 0;
}
1003.一道数学组合问题,比较简单。

#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
LL n, m, ans;
LL Cnm(LL n, LL m)//求组合数
{
	if (m > n / 2) //减小m
		m = n - m;
	LL a = 1, b = 1;
	for (int i = 0; i < m; i++)
	{
		a *= n - i;
		b *= (i + 1);
		if (a%b == 0){
			a /= b;
			b = 1;
		}
	}
	return  a / b;
}
int main()
{
	int i, j;
	while (cin >> n){
		if (n <= 3)cout << n << endl;
		else{
			m = 2 + (n - 4) / 3;
			ans = 0;
			for (int i = 1; i <= m; i++)
			{
				ans += Cnm(n - (i - 1) * 2, i);
			}
			cout << ans << endl;
		}
	}
	return 0;
}

有人用dp做出来了,好厉害。。。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;

LL a[65] = {0,1,2,3};

int main()
{
    int n;
    for(int i=4;i<=60;i++)
        a[i] = a[i-1]+ a[i-3]+1;
    while(cin>>n)
        cout<<a[n]<<endl;
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值