ACM-ICPC(11/8)

URAL 1005

给定一些石头的重量,要求分成两个部分最相近。二进制暴力枚举。

#include <bits/stdc++.h>

using namespace std;

int w[25];

int main()
{
   // freopen("in.txt","r",stdin);
    int n;
    scanf("%d",&n);

    int sum = 0;
    for(int i = 0; i < n; i++) {
        scanf("%d",&w[i]);
        sum +=w[i];
    }

    int ans = sum;
    for(int s = 0; s < 1<<n; s++) {
        int tmp = 0;
        for(int i = 0; i < n; i++) {
            if(s&(1<<i)) tmp+=w[i];
        }
        ans = min(ans,abs(2*tmp-sum));
    }

    cout<<ans<<endl;

    return 0;
}

URAL 1009

k进制,n位数,要求没有前导0,并且没有两个连续的0.

数据范围很小,暴力竟然超时了,队友的公式找了半天。要崩~~~

还好找出来了。

n = 1   ans = k-1

n = 2   ans = k*k -k

n = 3   ans = (k-1)*(ans2+ans1)

#include <bits/stdc++.h>

using namespace std;

int ans;
int n,k;
void dfs(int u,int x) {

    if(u==n) {
        ans++;
        return ;
    }

    if(x==0) {
        for(int i = 1; i <k; i++)
            dfs(u+1,i);
    }
    else {
        for(int i = 0;i<k; i++)
        {
            dfs(u+1,i);
        }
    }
}

int a[20];

int main()
{
    scanf("%d%d",&n,&k);

    a[1] = k - 1;
    a[2] = k*k - k;
    for(int i = 3; i <= n; i++)
        a[i] = (k-1)*(a[i-1]+a[i-2]);
    printf("%d\n",a[n]);

    return 0;
}

URAL 1011

售票员的人数是p%~q%不包含边界。求城市最少人数。

精度卡到炸~~~

#include <cstdio>
#include <cmath>

const double eps = 1e-9;

int main() {
    double p, q;
    int ans;
    scanf("%lf%lf", &p, &q);

    for (ans = 1; ; ++ans) {
        double least = ans * p / 100.0;
        int realLeast = (int) ceil(least);
        double most = ans * q / 100.0;
        int realMost = (int) floor(most);
        if (realMost >= realLeast && most - realMost > eps && realLeast - least > eps)
            break;
    }

    printf("%d\n", ans);

    return 0;
}

URAL 1010

横坐标1~n,纵坐标给出,求两个点,两点之间的点都在下方,两点的斜率绝对值最大。

其实就是相邻的点。

#include <bits/stdc++.h>

using namespace std;

long long a[100005];

int main()
{
    int n;
    scanf("%d",&n);

    for(int i = 1; i <= n;i++) cin>>a[i];

    long long ans = 0;
    int p;
    for(int i = 1; i <= n-1; i++) {
        if(abs(a[i+1]-a[i])>ans) {
            p = i;
            ans = abs(a[i+1] - a[i]);
        }
    }

    printf("%d %d\n",p,p+1);

    return 0;
}

时间: 2024-10-15 20:49:31

ACM-ICPC(11/8)的相关文章

《ACM/ICPC 算法训练教程》读书笔记一之数据结构(堆)

书籍简评:<ACM/ICPC 算法训练教程>这本书是余立功主编的,代码来自南京理工大学ACM集训队代码库,所以小编看过之后发现确实很实用,适合集训的时候刷题啊~~,当时是听了集训队final的意见买的,感觉还是不错滴. 相对于其他ACM书籍来说,当然如书名所言,这是一本算法训练书,有着大量的算法实战题目和代码,尽管小编还是发现了些许错误= =,有部分注释的语序习惯也有点不太合我的胃口.实战题目较多是比较水的题,但也正因此才能帮助不少新手入门,个人认为还是一本不错的算法书,当然自学还是需要下不少

2016 ACM/ICPC Asia Regional Shenyang Online 1007/HDU 5898 数位dp

odd-even number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 388    Accepted Submission(s): 212 Problem Description For a number,if the length of continuous odd digits is even and the length

hdu 5868 2016 ACM/ICPC Asia Regional Dalian Online 1001 (burnside引理 polya定理)

Different Circle Permutation Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 208    Accepted Submission(s): 101 Problem Description You may not know this but it's a fact that Xinghai Square is

ACM/ICPC 之 经典动规(POJ1088-滑雪)

POJ1088-滑雪 将每个滑雪点都看作起点,从最低点开始逐个由四周递推出到达此点的最长路径的长度,由该点记下. 理论上,也可以将每一点都看作终点,由最高点开始计数,有兴趣可以试试. 1 //经典DP-由高向低海拔滑雪-求最长路 2 //Memory:372K Time:32 Ms 3 #include<iostream> 4 #include<cstring> 5 #include<cstdio> 6 #include<algorithm> 7 using

hduoj 4710 Balls Rearrangement 2013 ACM/ICPC Asia Regional Online —— Warmup

http://acm.hdu.edu.cn/showproblem.php?pid=4710 Balls Rearrangement Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 735    Accepted Submission(s): 305 Problem Description Bob has N balls and A b

hduoj 4708 Rotation Lock Puzzle 2013 ACM/ICPC Asia Regional Online —— Warmup

http://acm.hdu.edu.cn/showproblem.php?pid=4708 Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description Alice was felling into a cave. She found a strange door with a number square m

HDU 5889 Barricade 【BFS+最小割 网络流】(2016 ACM/ICPC Asia Regional Qingdao Online)

Barricade Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 997    Accepted Submission(s): 306 Problem Description The empire is under attack again. The general of empire is planning to defend his

2014 ACM/ICPC Asia Regional Xi&#39;an Online

03 hdu5009 状态转移方程很好想,dp[i] = min(dp[j]+o[j~i]^2,dp[i]) ,o[j~i]表示从j到i颜色的种数. 普通的O(n*n)是会超时的,可以想到o[]最大为sqrt(n),问题是怎么快速找到从i开始往前2种颜色.三种.四种...o[]种的位置. 离散化之后,可以边走边记录某个数最后一个出现的位置,初始为-1,而所要求的位置就等于 if(last[a[i]]==-1) 该数没有出现过,num[i][1] = i,num[i][j+1] = num[i-1

2016年acm icpc 青岛站(中国石油大学(华东))总结

2016年acm icpc 青岛站(中国石油大学(华东))总结 2016年11月11日,在这个传说中所谓的单身节,我们出发了,做了整整一天的车来到了青岛.不得不提一下,作为一个身处华中沿海地区的童鞋,这是我人生第一次坐了这么久的高铁(真的无聊,无聊,无聊),然后到了青岛是晚上了(挤公交车真的是一件很刺激的事情). 海风那个吹, 海水那个涌, 冻得萌新瑟瑟发抖. 也许是知道我们要来挖石油的缘故吧, 老天爷特意给了我们三天晴天. 晚上也没啥事,就这么洗洗睡了,不对还有传说中学长带领学弟剁手呢! 第二

2016 ACM/ICPC Asia Regional Shenyang Online 1003/HDU 5894 数学/组合数/逆元

hannnnah_j’s Biological Test Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 802    Accepted Submission(s): 269 Problem Description hannnnah_j is a teacher in WL High school who teaches biolog