BestCoder#3

1001:Task schedule

思路:二分空余时间,注意二分的边界。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;
const int maxn =200000+10;
int n,m;
vector<int> frees;
bool have[maxn];

int main(){

    int ncase;
    cin >> ncase;
    while(ncase--){
        scanf("%d%d",&n,&m);
        frees.clear();
        int maxt = 0;
        memset(have,0,sizeof have);
        for(int i = 0; i < n; i++){
            int t;
            scanf("%d",&t);
            maxt = max(maxt,t);
            have[t] = 1;
        }
        for(int i = 1; i < maxn; i++){
            if(!have[i]) frees.push_back(i);
        }
        while(m--){
            int t;
            scanf("%d",&t);
            printf("%d\n",*(lower_bound(frees.begin(),frees.end(),t)));

        }
    }
    return 0;
}

1002:BestCoder Sequence

题意:让你从1~n的一个全排列中找出中位数为m的字串。

思路:先找出中位数的下标mid,分类讨论(下标):1,  1~mid-1  2,mid+1~n  3.x~mid~y(统计比中位数大的数的个数和比中位数小的数的个数差值)

累加即可。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;
const int maxn = 40000+10;
int n,m;
int num[maxn];
int cnt[2*maxn],cnt1[2*maxn];
int main(){

    while(~scanf("%d%d",&n,&m)){
        memset(cnt,0,sizeof cnt);
        memset(cnt1,0,sizeof cnt1);
        int mid;
        for(int i = 1; i <= n; i++){
            scanf("%d",&num[i]);
            if(num[i]==m) mid = i;
        }
        int bf = 0;
        long long  ans = 1;
        for(int i = mid-1; i >= 1; i--){
            if(num[i] > num[mid]){
                bf++;
                cnt[bf+maxn]++;
            }else{
                bf--;
                cnt[bf+maxn]++;
            }
        }
        ans += cnt[maxn];
        int bef = 0;
        for(int i = mid+1; i <= n; i++){
            if(num[i] > num[mid]){
                bef++;
                cnt1[bef+maxn]++;
                ans += cnt[maxn-bef];
            }else{
                bef--;
                cnt1[bef+maxn]++;
                ans += cnt[maxn-bef];
            }
        }
        ans += cnt1[maxn];
        cout<<ans<<endl;

    }
    return 0;
}

1004:Problem about GCD

题意:计算1~N 与N互质的数的乘积模上N的值

思路:打表发现规律,当N = 2*p^x 或者 p^x是答案为N-1 否则为1(要用大素数测试)

代码不会写,待补。

BestCoder#3,布布扣,bubuko.com

时间: 2024-12-26 14:46:24

BestCoder#3的相关文章

BestCoder Round #91

传送门:http://acm.hdu.edu.cn/search.php?field=problem&key=BestCoder+Round+%2391&source=1&searchmode=source A题:给你n种字母,每种字母有个权值vali,共cnti个,现在让你在里面挑出任意数量的字符,组合成一个字符串,该字符串的权值的计算方式为val1*1+val2*2+--+valn*n,让你输出字符串最大的权值是多少.这题很容易会有一个错误的贪心,就是把val为负的舍去,然后v

7-16 Bestcoder a Oracle

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 325    Accepted Submission(s): 139 Problem Description There is once a king and queen, rulers of an unnamed city, who have three daughters of co

HDU 5682/BestCoder Round #83 1003 zxa and leaf 二分+树

zxa and leaf Problem Description zxa have an unrooted tree with n nodes, including (n−1) undirected edges, whose nodes are numbered from 1 to n. The degree of each node is defined as the number of the edges connected to it, and each node whose degree

BestCoder Round #65 (ZYB&#39;s Game)

ZYB's Game Accepts: 672 Submissions: 1207 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Description ZYBZYBZYB played a game named NumberBombNumber BombNumberBomb with his classmates in hiking:a host keeps a

BestCoder 1st Anniversary

problem 1001 Souvenir Accepts: 901 Submissions: 2743 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) 问题描述 今天是BestCoder一周年纪念日. 比赛管理员Soda想要给每个参赛者准备一个纪念品. 商店里纪念品的单价是p元, 同时也可以花q元购买纪念品套装, 一个套装里有mm个纪念品. 今天总共有nn个参赛者, Soda想

hdu5418 BestCoder Round #52 (div.2) Victor and World ( floyd+状压dp)

Problem Description After trying hard for many years, Victor has finally received a pilot license. To have a celebration, he intends to buy himself an airplane and fly around the world. There are n countries on the earth, which are numbered from 1 to

【BestCoder】【Round#42】

模拟+链表+DP Orz AK爷faebdc A Growin要跟全部的n个人握手共2n杯香槟,再加上每对关系的两杯香槟,直接统计邻接矩阵中1的个数,再加2n就是answer 1 //BestCoder 42 A 2 #include<vector> 3 #include<cstdio> 4 #include<cstring> 5 #include<cstdlib> 6 #include<iostream> 7 #include<algor

bestcoder#37_1001 字符串,贪心

bestcoder#37_1001 字符串,dfs Rikka with string Accepts: 395 Submissions: 2281 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation,

【BestCoder】#29 C GTY&#39;s gay friends(区间和 随机数判重)

题目大意:可以到相应的场次查看中文翻译. 思路:其实这道题很简单,对于一个等差数列,我们要判断他是否每个数都出现,只需要判断区间和或者是最大值是否符合即可,但这边需要注意的便是中间的重复部分.最大值的判重必要性我就不知道了,而且我也不会做,目测做也超时. 这边就写一下偷别人的区间和+随机数判重的做法 其实这边判重的方法是给一个数加上一个超过1000007的权,然后在计算和的时候,便是唯一的. 否则例如下面的情况 10 11的和可以由5和16构成,既然两个的和可以被另外一个的两个数替代,那我们就找

hdu 5163 Taking Bus (BestCoder Round #27)

Taking Bus                                                               Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 501    Accepted Submission(s): 203 Problem Description Bestland has a v