【组队训练】2014鞍山区域赛

三题,排名98,铜尾……

说实话,这样下去真的很害怕,感觉每次都是铜尾阿= = 等正式比赛时一点失误不就tm又铁了嘛。。。。

刚开始很多人过I题,zr看了下直接写的。1A

然后部分人过了E,我看了下,水dp,随便敲了下,1A

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
const int N = 105;

int a[N];
int s[N][N];
int dp[N][N];

int main()
{
    //freopen("in.txt", "r", stdin);
    int T;
    scanf("%d", &T);
    while (T--) {
        int n, m;
        scanf("%d%d", &n, &m);
        for (int i = 1; i <= m; ++i) {
            for (int j = 1; j <= m; ++j) {
                scanf("%d", &s[i][j]);
            }
        }
        for (int i = 1; i <= n; ++i) {
            scanf("%d", a+i);
        }
        memset(dp, -1, sizeof dp);
        if (a[1] != -1) dp[1][a[1]] = 0;
        else {
            for (int j = 1; j <= m; ++j) {
                dp[1][j] = 0;
            }
        }
        for (int i = 2; i <= n; ++i) {

            if (a[i] != -1) {
                for (int k = 1; k <= m; ++k) {
                    if (dp[i-1][k] < 0) continue;
                    dp[i][a[i]] = max(dp[i][a[i]], dp[i-1][k] + s[k][a[i]]);
                }
                continue;
            }
            for (int j = 1; j <= m; ++j) {
                for (int k = 1; k <= m; ++k) {
                    if (dp[i-1][k] < 0) continue;
                    dp[i][j] = max(dp[i][j], dp[i-1][k] + s[k][j]);
                }
            }
        }
        int ans = 0;
        for (int j = 1; j <= m; ++j) {
            ans = max(ans, dp[n][j]);
        }
        printf("%d\n", ans);

    }
    return 0;
}
View Code

然后就很坎坷了- -

D题我们讨论得出重心是每个点的和除以点的个数,和只需要找n-k个数就可以了,剩下的放在重心就好了。

zr贪心写了一发,没过。

我看好了B题(大模拟),想写一下,zr说他写,让我想其他题。

于是我想了下D,觉得选择的区域应该是连续的,遍历一便就可以了。这时zrB题wa了。我写D,也wa……

很尴尬的时刻QAQ

查了半个小时,查出来少了回车(妈蛋啊啊啊)3A

#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
//#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
#define PF(x) cout << "debug: " << x << " ";
#define EL cout << endl;
#define PC(x) puts(x);
typedef long long ll;
#define CLR(x, v) sizeof (x, v, sizeof(x))
using namespace std;
const int INF = 0x5f5f5f5f;
const int  N= 2e5 + 10;
const int mod=1e9 + 7;
const int maxn = 5e4 + 10;

double a[maxn];
double sum[maxn];
int main()
{
    //freopen("in.txt","r",stdin);
    int T;
    scanf("%d", &T);
    while (T--) {
        int n ,k;
        scanf("%d%d", &n, &k);
        for (int i = 1; i <= n; ++i) {
            scanf("%lf", a+i);
        }
        if (n <= k+1) {
            printf("0\n");
            continue;
        }
        sort(a+1, a+1+n);
        for (int i = 1; i <= n; ++i) { // qianzhuihe
            sum[i] = sum[i-1] + a[i];
        }
        int x = n-k;

        double tot = 0, tmp = 0;
        for (int i = 1; i <= x; ++i) {
            tot += a[i];
            tmp += a[i]*a[i];
        }
        double cer;
        cer = tot / x; // zhongxin
        tmp = tmp + cer * cer * x - 2 * cer * sum[x];
        double ans = tmp;
        for (int i = x+1; i <= n; ++i) {
            tmp = tmp + 2*cer*(sum[i-1]-sum[i-1-x]) - cer*cer*x - a[i-x]*a[i-x];
            tot = tot + a[i] - a[i-x];
            cer = tot / x;
            tmp = tmp + a[i]*a[i] - 2*cer*(sum[i]-sum[i-x]) + cer*cer*x;
            ans = min(ans, tmp);
        }
        printf("%.10f\n", ans);
    }

    return 0;
}
View Code

 

B题题意不明确,试了好多种题意,还是没过。(赛后发现代码也确实有一些问题- -

 

一道数论相对简单的题没过,学弟果然还是弱一些= =

 

sigh……

posted @ 2016-08-31 17:42  我不吃饼干呀  阅读(254)  评论(0编辑  收藏  举报