码迷,mamicode.com
首页 > 其他好文 > 详细

Summer training round2 #8(Training26)

时间:2017-08-15 23:32:47      阅读:342      评论:0      收藏:0      [点我收藏+]

标签:==   i++   sum   ace   c++   模拟   air   alt   turn   

A:贪心DFS

先从最远的搜起 如果一个点的value>=2 就ans++

D:并查集

E:大模拟

F:快速幂

技术分享
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL > pLL;
const LL MOD1 = 1e9 + 7, MOD2 = 1e9 + 9;
int n, a[1000], vis[1000], i, j, k;
set<pLL> st;
LL QuickPow(LL a, LL b, LL MOD) {
    LL res = 1;
    while(b) {
        if(b & 1) res = (res + a) % MOD;
        a = (a * a) % MOD;
        b >>= 1;
    }
    return res;
}
int main() {
    freopen("numbereater.in", "r", stdin);
    freopen("numbereater.out", "w", stdout);
    scanf("%d", &n);
    for(i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    LL sum1, sum2;
    for(i = 1; i <= n; i++) {
        memset(vis, 0, sizeof(vis));
        sum1 = 0; sum2 = 0;
        for(j = i; j <= n; j++) {
            if(!vis[a[j]]) {
                sum1 = (sum1 + QuickPow(a[j], a[j], MOD1)) % MOD1;
                sum2 = (sum2 + QuickPow(a[j], a[j], MOD2)) % MOD2;
                vis[a[j]] = 1;
                st.insert(make_pair(sum1, sum2));
            }
        }
    }
    printf("%d\n", st.size());
    return 0;
}
View Code

K:暴力

技术分享
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#define INF 2139062143
#define inf -2139062144
#define ll long long
using namespace std;
int a[300];
int n;
bool over() {
    for(int i=0; i<n; i++) {
        if(a[i] != 1)    return false;
    }
    return true;
}
int main() {
    int i,j,k;

    freopen("table.in", "r", stdin);
    freopen("table.out", "w", stdout);
//    for(n=299; n<=299; n+=2) {
    scanf("%d",&n);
    if(n % 2 == 0) {
        printf("IMPOSSIBLE\n");
        return 0;
    }
    memset(a,0,sizeof a);
    a[0] = n;
    int cnt = 0;
    while(!over()) {

        int ma = inf;
        int b[300];
        for(i=0; i<n; i++) {
            ma = max(a[i],ma);
            b[i] = a[i];
        }
        for(i=0; i<n; i++) {
            if(a[i] == ma) {
                b[i] -= 2;
                b[(i-1+n)%n] ++;
                b[(i+1+n)%n] ++;
                if(cnt == 0) {
                    cnt = 1;
                } else {
                    printf(" ");
                }
                printf("%d",i + 1);
            }
        }
        for(i=0; i<n; i++)    a[i] = b[i];
    }
    printf("\n");
//    }

    return 0;
}
View Code

 

Summer training round2 #8(Training26)

标签:==   i++   sum   ace   c++   模拟   air   alt   turn   

原文地址:http://www.cnblogs.com/Aragaki/p/7368316.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!