HDU 5045 5047 5050 5053(上海网络赛E,F,I,L)

HDU 5045 5047 5050 5053

太菜了,名额差点没保住,吓尿。。赶紧开刷树链抛分

5045:状压DP,压缩10个人,由于两个人不能差2以上,所以可以用01表示

5047:推推公式即可,每次交线多4条

5050:求GCD,用java大叔即可

5053:签到题

代码:

5045:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int N = 1025;

int t, n, m, vis[N][N];
double dp[N][N], g[15][N];

double dfs(int u, int num) {
    if (u == (1<<n) - 1) u = 0;
    if (vis[u][num]) return dp[u][num];
    vis[u][num] = 1;
    if (num == m) return dp[u][num] = 0;
    dp[u][num] = 0;
    for (int i = 0; i < n; i++) {
        if (u&(1<<i)) continue;
        dp[u][num] = max(dp[u][num], dfs(u|(1<<i), num + 1) + g[i][num]);
    }
    return dp[u][num];
}

int main() {
    int cas = 0;
    scanf("%d", &t);
    while (t--) {
        scanf("%d%d", &n, &m);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                scanf("%lf", &g[i][j]);
            }
        }
        memset(vis, 0, sizeof(vis));
        printf("Case #%d: %.5lf\n", ++cas, dfs(0, 0));
    }
    return 0;
}

5047:

#include <cstdio>
#include <cstring>

typedef long long ll;

const ll MOD = 100000000;
int t;
ll n;

struct Num {
    ll num[5];
    int len;
    Num() {
        len = 0;
        memset(num, 0, sizeof(num));
    }
    void init(ll x) {
        len = 0;
        if (x == 0) {
            len = 1;
            num[0] = 0;
            return;
        }
        while (x) {
            num[len++] = x % MOD;
            x /= MOD;
        }
    }

    Num operator * (Num c) {
        Num ans;
        for (int i = 0; i < len; i++) {
            for (int j = 0; j < c.len; j++) {
                ans.num[i + j] += num[i] * c.num[j];
            }
        }
        ans.len = len + c.len;
        for (int i = 0; i < ans.len; i++) {
            ans.num[i + 1] += ans.num[i] / MOD;
            ans.num[i] %= MOD;
        }
        return ans;
    }

    void add() {
        while (len && num[len - 1] == 0) len--;
        num[0] += 2;
        for (int i = 0; i < len; i++) {
            num[i + 1] += num[i] / MOD;
            num[i] %= MOD;
        }
        if (num[len]) len++;
        while (len && num[len - 1] == 0) len--;
    }

    void print() {
        while (len && num[len - 1] == 0) len--;
        for (int i = len - 1; i >= 0; i--) {
            if (i == len - 1) printf("%I64d", num[i]);
            else printf("%08I64d", num[i]);
        }
        printf("\n");
    }
} A, B;

int main() {
    int cas = 0;
    scanf("%d", &t);
    while (t--) {
        scanf("%I64d", &n);
        A.init(n - 1);
        B.init(8 * n + 1);
        Num c = (A * B);
        c.add();
        printf("Case #%d: ", ++cas);
        c.print();
    }
    return 0;
}

5050:

import java.util.*;
import java.math.*;
import java.io.*;

public class Main {
    public static BigInteger gcd(BigInteger a, BigInteger b) {
        if (b.equals(BigInteger.valueOf(0)) == true) return a;
        return gcd(b, a.mod(b));
    }
    public static void main(String args[]) {
        Scanner cin = new Scanner(System.in);
        int t;
        t = cin.nextInt();
        String a, b;
        BigInteger aa, bb;
        for (int cas = 1; cas <= t; cas++) {
            a = cin.next();
            b = cin.next();
            aa = BigInteger.valueOf(0);
            bb = BigInteger.valueOf(0);
            for (int i = 0; i < a.length(); i++) {
                aa = aa.multiply(BigInteger.valueOf(2));
                if (a.charAt(i) == '1') aa = aa.add(BigInteger.valueOf(1));
            }
            for (int i = 0; i < b.length(); i++) {
                bb = bb.multiply(BigInteger.valueOf(2));
                if (b.charAt(i) == '1') bb = bb.add(BigInteger.valueOf(1));
            }
            BigInteger tmp = gcd(aa, bb);
            String ans = "";
            while (tmp.equals(BigInteger.valueOf(0)) == false) {
                if (tmp.mod(BigInteger.valueOf(2)).equals(BigInteger.valueOf(1))) ans += '1';
                else ans += '0';
                tmp = tmp.divide(BigInteger.valueOf(2));
            }
            System.out.print("Case #");
            System.out.print(cas);
            System.out.print(": ");
            for (int i = ans.length() - 1; i >= 0; i--)
                System.out.print(ans.charAt(i));
            System.out.println();
        }
    }
}

5053:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

typedef long long ll;

int t;
ll a, b;

int main() {
    int cas = 0;
    scanf("%d", &t);
    while (t--) {
        scanf("%I64d%I64d", &a, &b);
        ll sum = 0;
        for (ll i = a; i <= b; i++)
            sum += i * i * i;
        printf("Case #%d: %I64d\n", ++cas, sum);
    }
    return 0;
}
时间: 2024-08-28 20:40:11

HDU 5045 5047 5050 5053(上海网络赛E,F,I,L)的相关文章

HDU 5045 状压DP 上海网赛

比赛的时候想的是把n个n个的题目进行状压 但这样不能讲究顺序,当时精神面貌也不好,真是挫死了 其实此题的另一个角度就是一个n个数的排列,如果我对n个人进行状压,外面套一个按题目循序渐进的大循环,那么,在当前做第i个题目,前i-1个题目已经做完,然后做完的人的状态为j, j可能是1110 1101 1011什么的(假设已经做了三道题),因为我这样就可以只管状态而不管顺序了,我只取这种状态下的最大值,他究竟是怎么个顺序排列我不用管 到此...好像问题就没有什么问题了,这种做法重复 m/n次最后把剩余

hdu 6152 : Friend-Graph (2017 CCPC网络赛 1003)

题目链接 裸的结论题.百度 Ramsey定理.刚学过之后以为在哪也不会用到23333333333,没想到今天网络赛居然出了.顺利在题面更改前A掉~~~(我觉得要不是我开机慢+编译慢+中间暂时死机,我还能再早几分钟过掉它 #include<bits/stdc++.h> using namespace std; int g[8][8]; int n; void solve() { for(int i=1; i<=n; i++) for(int j=i+1; j<=n; j++) for

2014上海网络赛 HDU 5053 the Sum of Cube

水 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include<math.h> 4 #include<iostream> 5 #define LL long long 6 using namespace std; 7 8 int main() 9 { 10 int t; 11 int a,b; 12 int cas; 13 LL sum; 14 while(~scanf("%d",&

hdu 5053 the Sum of Cube(上海网络赛)

the Sum of Cube Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 405    Accepted Submission(s): 224 Problem Description A range is given, the begin and the end are both integers. You should sum

2015上海网络赛 HDU 5478 Can you find it 数学

HDU 5478 Can you find it 题意略. 思路:先求出n = 1 时候满足条件的(a,b), 最多只有20W对,然后对每一对进行循环节判断即可 1 #include <iostream> 2 #include <cstdio> 3 #include <fstream> 4 #include <algorithm> 5 #include <cmath> 6 #include <deque> 7 #include <

2015上海网络赛 HDU 5475 An easy problem 线段树

题意就不说了 思路:线段树,维护区间乘积.2操作就将要除的点更新为1. 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<algorithm> 6 #include<queue> 7 #include<vector> 8 #include<set> 9 #include<stri

HDU 5044(2014 ACM-ICPC上海网络赛)

题意:给定一个树形图,节点10^5,有两种操作,一种是把某两点间路径(路径必定唯一)上所有点的权值增加一个固定值. 另一种也是相同操作,不同的是给边加权值.操作次数10^5.求操作过后,每个点和每条边的权值. 分析:此题时间卡得非常紧,最好用输入外挂,最好不要用RMQ来求解LCA. 此题是典型的在线LCA问题,先讲讲在线LCA要怎么做. 在线LCA有两种方法,第一种比较常见,即将其转化成RMA问题. 先对树形图进行深度优先遍历,遍历过程记录路线中点的途经序列,每个非叶子节点会在序列中出现多次,从

hdu 5881 Tea (2016 acm 青岛网络赛)

原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=5881 Tea Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 451    Accepted Submission(s): 124 Problem Description Tea is good. Tea is life. Tea is e

HDU 5014 Number Sequence(西安网络赛H题)

HDU 5014 Number Sequence 题目链接 思路:对于0-n,尽量不让二进制中的1互相消掉就是最优的,那么只要两个数只要互补就可以了,这样每次从最大的数字,可以找到和他互补的数字,然后这个区间就能确定了,然后剩下的递归下去为一个子问题去解决 代码: #include <cstdio> #include <cstring> const int N = 100005; int n, a[N], ans[N]; int cnt[N]; int count(int x) {