2018年第四阶段组队训练赛第七场

A: Secret of Chocolate Poles

题目描述

Wendy, the master of a chocolate shop, is thinking of displaying poles of chocolate disks in the showcase. She can use three kinds of chocolate disks: white thin disks, dark thin disks, and dark thick disks. The thin disks are 1 cm thick, and the thick disks are k cm thick. Disks will be piled in glass cylinders.
Each pole should satisfy the following conditions for her secret mission, which we cannot tell.
? A pole should consist of at least one disk.
? The total thickness of disks in a pole should be less than or equal to l cm.
? The top disk and the bottom disk of a pole should be dark.
? A disk directly upon a white disk should be dark and vice versa.
As examples, six side views of poles are drawn in Figure A.1. These are the only possible side views she can make when l = 5 and k = 3.

Figure A.1. Six chocolate poles corresponding to Sample Input 1
Your task is to count the number of distinct side views she can make for given l and k to help her accomplish her secret mission.

输入

The input consists of a single test case in the following format.
l k
Here, the maximum possible total thickness of disks in a pole is l cm, and the thickness of the thick disks is k cm. l and k are integers satisfying 1 ≤ l ≤ 100 and 2 ≤ k ≤ 10.

输出

Output the number of possible distinct patterns.

样例输入

5 3

样例输出

6分析:我们理解的是排列组合 列举1和k的个数 i和j个的时候 A(i+j)/(A(i)*A(j)数会很大 还开了java我最开始。。。还妄想dfs。。。写了发TLE
import java.util.*;
import java.math.BigInteger;
public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner cin = new Scanner(System.in);
        BigInteger[]fac=new BigInteger[60];
        fac[0]=BigInteger.valueOf(1);
        BigInteger tmp;
        for(int i=1;i<60;i++) {
            tmp=BigInteger.valueOf(i);
            fac[i]=fac[i-1].multiply(tmp);
        }
        int l,k;
        l= cin.nextInt();
        k=cin.nextInt();
        int flag=0;
        long aa=0;
        BigInteger ans=BigInteger.valueOf(0);
        if(l==1)    aa=1;
        else if(l<k) aa=(l-1)/2+1;
        else if(l==k)   aa=(l-1)/2+2;
        else
        {
            flag=1;
            BigInteger tt,pp;
            for(int i=0;i*(k+1)<=(l-1);i++)
            {
                for(int j=0;j*2<=(l-1-i*(k+1));j++)
                {
                    tt=fac[i].multiply(fac[j]);
                    pp=fac[i+j].divide(tt);
                    ans=ans.add(pp);
                }
            }
            for(int i=0;i*2<=(l-k);i++)
            {
                for(int j=0;j*(k+1)<=(l-k-i*2);j++){
                    tt=fac[i].multiply(fac[j]);
                    pp=fac[i+j].divide(tt);
                    ans=ans.add(pp);
                }
            }
        }
        if(flag==1)
            System.out.println(ans);
        else
        {
            ans=BigInteger.valueOf(aa);
            System.out.println(ans);
        }

    }

}

正解应该是dp 超简单的(转)

#include<cstdio>
typedef __int128 lll;
const int N=200;
lll f[N][2],ans;//dark white
int l,k,i;
void write(lll x){
    if(x>=10)write(x/10);
    x%=10;
    printf("%d",(int)(x));
}
int main(){
    scanf("%d%d",&l,&k);
    f[1][0]++;
    f[k][0]++;
    for(i=1;i<=l;i++){
        f[i+1][1]+=f[i][0];
        f[i+1][0]+=f[i][1];
        f[i+k][0]+=f[i][1];
    }
    for(i=1;i<=l;i++)ans+=f[i][0];
    write(ans);
}

————————————————————————————————

B: Parallel Lines

题目描述

Given an even number of distinct planar points, consider coupling all of the points into pairs.
All the possible couplings are to be considered as long as all the given points are coupled to one and only one other point.
When lines are drawn connecting the two points of all the coupled point pairs, some of the drawn lines can be parallel to some others. Your task is to ?nd the maximum number of parallel line pairs considering all the possible couplings of the points. 
For the case given in the ?rst sample input with four points, there are three patterns of point couplings as shown in Figure B.1. The numbers of parallel line pairs are 0, 0, and 1, from the left. So the maximum is 1.

Figure B.1. All three possible couplings for Sample Input 1
For the case given in the second sample input with eight points, the points can be coupled as shown in Figure B.2. With such a point pairing, all four lines are parallel to one another. In other words, the six line pairs (L1, L2), (L1, L3), (L1, L4), (L2, L3), (L2, L4) and (L3, L4) are parallel. So the maximum number of parallel line pairs, in this case, is 6.

输入

The input consists of a single test case of the following format.
m
x1 y1
.
.
.
xm ym

Figure B.2. Maximizing the number of parallel line pairs for Sample Input 2
The first line contains an even integer m, which is the number of points (2 ≤ m ≤ 16). Each of the following m lines gives the coordinates of a point. Integers xi and yi (?1000 ≤ xi ≤ 1000,?1000 ≤ yi ≤ 1000) in the i-th line of them give the x- and y-coordinates, respectively, of the i-th point.
The positions of points are all different, that is, xi ≠ xj or yi ≠ yj holds for all i ≠ j. Furthermore, No three points lie on a single line.

输出

Output the maximum possible number of parallel line pairs stated above, in one line.

样例输入

4
0 0
1 1
0 2
2 4

样例输出

1

昨天刚做了一道几何的 向量有关的题 感觉瞬间就来了主要是dfs点的组合比较耗费时间还用了pair来存一个边的两个点
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node
{
    int x,y;
} Point[20];
int n,ans=-1;
bool vis[20];
vector<pair<int,int> >line;
void countt()
{
    int tmp=0;
    for(int i=0; i<line.size(); i++)
    {
        int x1=Point[line[i].first].x-Point[line[i].second].x;
        int y1=Point[line[i].first].y-Point[line[i].second].y;
        for(int j=i+1; j<line.size(); j++)
        {
            int x2=Point[line[j].first].x-Point[line[j].second].x;
            int y2=Point[line[j].first].y-Point[line[j].second].y;
            if(x1*y2==x2*y1)
            {
                tmp++;
            }
        }
    }
    ans=max(ans,tmp);
}
void dfs(int now)
{
    if(now==n+1)
    {
//        for(int i=0;i<line.size();i++)
//        {
//            cout<<line[i].first<<" "<<line[i].second<<endl;
//        }
//        cout<<"jasahdfkjassbfj"<<endl;
        countt();
        return;
    }
    if(vis[now])
    {
        dfs(now+1);
    }
    else
    {
        for(int i=1; i<=n; i++)
        {
            if(vis[i]||i==now)
            {
                continue;
            }
            line.push_back(make_pair(now,i));
            vis[now]=vis[i]=1;
            dfs(now+1);
            line.pop_back();
            vis[now]=vis[i]=0;
        }
    }
}
int main()
{
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d %d",&Point[i].x,&Point[i].y);
    }
    dfs(1);
    printf("%d\n",ans);
    return 0;
}
 

————————————————————————————————

C: Medical Checkup

题目描述

Students of the university have to go for a medical checkup, consisting of lots of checkup items,numbered 1, 2, 3, and so on.
Students are now forming a long queue, waiting for the checkup to start. Students are also numbered 1, 2, 3, and so on, from the top of the queue. They have to undergo checkup items in the order of the item numbers, not skipping any of them nor changing the order. The order of students should not be changed either.
Multiple checkup items can be carried out in parallel, but each item can be carried out for only one student at a time. Students have to wait in queues of their next checkup items until all the others before them finish.
Each of the students is associated with an integer value called health condition. For a student with the health condition h, it takes h minutes to finish each of the checkup items. You may assume that no interval is needed between two students on the same checkup item or two checkup items for a single student. 
Your task is to find the items students are being checked up or waiting for at a specified time t.

输入

The input consists of a single test case in the following format.
n t
h1
.
.
.
hn
n and t are integers. n is the number of the students (1 ≤ n ≤ 105). t specifies the time of our concern (0 ≤ t ≤ 109). For each i, the integer hi is the health condition of student i(1 ≤ hi ≤ 109).

输出

Output n lines each containing a single integer. The i-th line should contain the checkup item number of the item which the student i is being checked up or is waiting for, at (t+0.5) minutes after the checkup starts. You may assume that all the students are yet to finish some of the checkup items at that moment.

样例输入

3 20
5
7
3

样例输出

5
3
2
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N=100050;
int n;
ll h[N],sum[N],t;
int main()
{
    scanf("%d %lld",&n,&t);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&h[i]);
        sum[i]=sum[i-1]+h[i];
    }
    for(int i=1;i<=n;i++)
    {
        ll tt=t-sum[i];
        if(tt<0)
        {
            printf("1\n");
            continue;
        }
        else
        {
            if(h[i]<h[i-1])
            {
                h[i]+=(h[i-1]-h[i]);
            }
            ll ans=tt/h[i];
            ans+=2;
            printf("%lld\n",ans);
        }
    }
    return 0;
}
 

原文地址:https://www.cnblogs.com/hao-tian/p/9556285.html

时间: 2024-08-30 04:04:27

2018年第四阶段组队训练赛第七场的相关文章

2018年第四阶段组队训练赛第三场(BAPC2017 Preliminaries)

D.Disastrous Doubling 题目描述 A scientist, E. Collie, is going to do some experiments with bacteria.Right now, she has one bacterium. She already knows that this species of bacteria doubles itself every hour. Hence, after one hour there will be 2 bacter

第四阶段组队训练赛第六场( 题源:UKIEPC2017)

A: Alien Sunset 题目描述 Following tremendous advances in space flight control software and equally impressive innova- tions in reality TV crowdfunding, humans have successfully settled a number of planets, moons, asteroids, and various other kinds of fu

UPC2018组队训练赛第七场

题目来自ICPC 2017 Japan Tsukuba A题:Secret of Chocolate Poles 有三种巧克力,分别是厚度为1的白色巧克力,厚度为1或者k的黑色巧克力.要求把巧克力放到高度为 l 的盒子里,并且要黑白相间,底部和顶部必须都是黑色的 当l=1,ans=1:当l<k,ans=(l-1)/2+1:当l=k,ans=(l-1)/2+2;当l>k时,就可以转化成排列组合问题了,枚举厚度为k的黑色巧克力数目i,然后对于每一种情况,再枚举厚度为1的黑色巧克力的数目j,那么此时

Contest1814 - 2019年我能变强组队训练赛第七场

Scores of Final Examination On-Screen Keyboard Tally Counters Balance Scale #pragma GCC optimize(3,"Ofast","inline") #include <bits/stdc++.h> using namespace std; typedef long long ll; unordered_map<ll,bool> m1; int n,m,cnt

HDU 5371 (2015多校联合训练赛第七场1003)Hotaru&#39;s problem(manacher+二分/枚举)

HDU 5371 题意: 定义一个序列为N序列:这个序列按分作三部分,第一部分与第三部分相同,第一部分与第二部分对称. 现在给你一个长为n(n<10^5)的序列,求出该序列中N序列的最大长度. 思路: 来自官方题解:修正了一些题解错别字(误 先用求回文串的Manacher算法,求出以第i个点为中心的回文串长度,记录到数组p中 要满足题目所要求的内容,需要使得两个相邻的回文串,共享中间的一部分,也就是说,左边的回文串长度的一半,要大于等于共享部分的长度,右边回文串也是一样. 因为我们已经记录下来以

HDU 5371 (2015多校联合训练赛第七场1003)Hotaru&amp;#39;s problem(manacher+二分/枚举)

pid=5371">HDU 5371 题意: 定义一个序列为N序列:这个序列按分作三部分,第一部分与第三部分同样,第一部分与第二部分对称. 如今给你一个长为n(n<10^5)的序列,求出该序列中N序列的最大长度. 思路: 来自官方题解:修正了一些题解错别字(误 先用求回文串的Manacher算法.求出以第i个点为中心的回文串长度.记录到数组p中 要满足题目所要求的内容.须要使得两个相邻的回文串,共享中间的一部分,也就是说.左边的回文串长度的一半,要大于等于共享部分的长度,右边回文串也

HDU 4941 Magical Forest(map映射+二分查找)杭电多校训练赛第七场1007

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4941 解题报告:给你一个n*m的矩阵,矩阵的一些方格中有水果,每个水果有一个能量值,现在有三种操作,第一种是行交换操作,就是把矩阵的两行进行交换,另一种是列交换操作,注意两种操作都要求行或列至少要有一个水果,第三种操作是查找,询问第A行B列的水果的能量值,如果查询的位置没有水果,则输出0. 因为n和m都很大,达到了2*10^9,但水果最多一共只有10^5个,我的做法是直接用结构体存了之后排序,然后m

Contest1539 - 2019年我能变强组队训练赛第十一场

Greater New York 2012 Hailstone HOTPO #pragma GCC optimize(3,"Ofast","inline") #include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n; int T; cin>>T; while(T--) { ll k; scanf("%lld %lld&q

北方大学 ACM 多校训练赛 第七场 C Castle(LCA)

[题意]给你N个点,N条不同的边,Q次询问,求出u,v之间的最短路. [分析]题意很简单,就是求最短路,但是Q次啊,暴力DIJ?当然不行,观察到这个题边的数目和点的数目是相同的,也就是说这个图是由一棵树加了一条边而形成的.而对于一棵树,如果有Q次询问最短路,那就可以用LCA来做,复杂度QlogN,但是现在加了一条边,可能会使有些点之间的路径变短.假设多加的这条边的两个端点是U,V,那么对于询问的X,Y,有这么三种情况,直接过LCA,或者经过U,V,详情见代码. #include <bits/st