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 find the maximum number of parallel line pairs considering all the possible couplings of the points. 
For the case given in the first 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;
}
 

 

posted @ 2018-08-29 18:57  zangzang  阅读(173)  评论(0编辑  收藏  举报