A. Holidays
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

On the planet Mars a year lasts exactly n days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars.

Input

The first line of the input contains a positive integer n (1 ≤ n ≤ 1 000 000) — the number of days in a year on Mars.

Output

Print two integers — the minimum possible and the maximum possible number of days off per year on Mars.

Examples
Input
14
Output
4 4
Input
2
Output
0 2
Note

In the first sample there are 14 days in a year on Mars, and therefore independently of the day a year starts with there will be exactly 4 days off .

In the second sample there are only 2 days in a year on Mars, and they can both be either work days or days off.

思路分析:水题,但要注意细节处理

代码:

#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
    int n;
    int mina ,maxn;
    while(~scanf("%d",&n))
    {
        if(n==0)
        mina=0,maxn=0;
       else if(n==1)
        mina=0,maxn=1;
        else if(n<=5)
        {mina=0,maxn=2;}
        else if(n<=7) {mina=n-5,maxn=2;}
        else
        {
           int t=n/7;
           int k=n%7;
            if(k==6) mina=2*t+1;
            else mina=2*t;
           if(k>=2) maxn=(t+1)*2;
           else maxn=mina+k;
        }
        cout<<mina<<" "<<maxn<<endl;
    }
    return 0;
}

B. Game of Robots
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.

At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.

Your task is to determine the k-th identifier to be pronounced.

Input

The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(2·109, n·(n + 1) / 2).

The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different.

Output

Print the k-th pronounced identifier (assume that the numeration starts from 1).

Examples
Input
2 2
1 2
Output
1
Input
4 5
10 4 18 3
Output
4
Note

In the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.

In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4.

思路分析:先暴力枚举判断k落在哪一个区间里,然后输出

代码:

#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn=100000+100;
__int64  a[maxn];
int main()
{
    __int64 n,k,i,t;
    while(~scanf("%I64d%I64d",&n,&k))
    {
        for( i=1;i<=n;i++)
            scanf("%I64d",&a[i]);
        for( i=1;i<=k;i++)
        {
            t=i*(i+1)/2;
            if(t>=k) break;
        }
         int m=t-k;
         printf("%I64d\n",a[i-m]);
    }
    return 0;
}

C. Cinema
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 1 to 109.

In the evening after the conference, all n scientists decided to go to the cinema. There are m movies in the cinema they came to. Each of the movies is characterized by two distinct numbers — the index of audio language and the index of subtitles language. The scientist, who came to the movie, will be very pleased if he knows the audio language of the movie, will be almost satisfied if he knows the language of subtitles and will be not satisfied if he does not know neither one nor the other (note that the audio language and the subtitles language for each movie are always different).

Scientists decided to go together to the same movie. You have to help them choose the movie, such that the number of very pleased scientists is maximum possible. If there are several such movies, select among them one that will maximize the number of almost satisfied scientists.

Input

The first line of the input contains a positive integer n (1 ≤ n ≤ 200 000) — the number of scientists.

The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the index of a language, which the i-th scientist knows.

The third line contains a positive integer m (1 ≤ m ≤ 200 000) — the number of movies in the cinema.

The fourth line contains m positive integers b1, b2, ..., bm (1 ≤ bj ≤ 109), where bj is the index of the audio language of the j-th movie.

The fifth line contains m positive integers c1, c2, ..., cm (1 ≤ cj ≤ 109), where cj is the index of subtitles language of the j-th movie.

It is guaranteed that audio languages and subtitles language are different for each movie, that is bj ≠ cj.

Output

Print the single integer — the index of a movie to which scientists should go. After viewing this movie the number of very pleased scientists should be maximum possible. If in the cinema there are several such movies, you need to choose among them one, after viewing which there will be the maximum possible number of almost satisfied scientists.

If there are several possible answers print any of them.

Examples
Input
3
2 3 2
2
3 2
2 3
Output
2
Input
6
6 3 1 1 3 7
5
1 2 3 4 5
2 3 4 5 1
Output
1
Note

In the first sample, scientists must go to the movie with the index 2, as in such case the 1-th and the 3-rd scientists will be very pleased and the 2-nd scientist will be almost satisfied.

In the second test case scientists can go either to the movie with the index 1 or the index 3. After viewing any of these movies exactly two scientists will be very pleased and all the others will be not satisfied.

思路分析:刚开始我还以为是背包,后来发现想多了,直接 用map存储每一种语言会的科学家的个数,然后放到movie结构体里

先按audio后按sub排序,输出最大的即可。

tip:sort cmp里面不能出现>=或<=,否则会超时,因为一旦出现a==b的情况,sort函数就没法判断谁在前谁在后了

代码:

#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
const int maxn=200000+100;
struct nod
{
    int ID;
    __int64 aud;
    __int64 sub;
};
nod m[maxn];
bool cmp(nod x,nod y)
{
    return  (x.aud==y.aud)?(x.sub>y.sub):(x.aud>y.aud);
}
map<__int64,int> a;
int llll;
int main()
{
       int n,ma;
        __int64 number;
       scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%I64d",&number);
            a[number]++;
        }
        scanf("%d",&ma);
        for(int i=1;i<=ma;i++)
        {
            scanf("%I64d",&number);
            m[i].aud=a[number];
            m[i].ID=i;
        }
        for(int i=1;i<=ma;i++)
        {
            scanf("%I64d",&number);
            m[i].sub=a[number];
        }
        sort(m+1,m+ma+1,cmp);
        printf("%d\n",m[1].ID);
    return 0;
}

D1. Magic Powder - 1
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too difficult in large constraints, you can write solution to the simplified version only.

Waking up in the morning, Apollinaria decided to bake cookies. To bake one cookie, she needs n ingredients, and for each ingredient she knows the value ai — how many grams of this ingredient one needs to bake a cookie. To prepare one cookie Apollinaria needs to use all n ingredients.

Apollinaria has bi gram of the i-th ingredient. Also she has k grams of a magic powder. Each gram of magic powder can be turned to exactly 1 gram of any of the n ingredients and can be used for baking cookies.

Your task is to determine the maximum number of cookies, which Apollinaria is able to bake using the ingredients that she has and the magic powder.

Input

The first line of the input contains two positive integers n and k (1 ≤ n, k ≤ 1000) — the number of ingredients and the number of grams of the magic powder.

The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 1000), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie.

The third line contains the sequence b1, b2, ..., bn (1 ≤ bi ≤ 1000), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has.

Output

Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder.

Examples
Input
3 1
2 1 4
11 3 16
Output
4
Input
4 3
4 3 5 6
11 12 14 20
Output
3
Note

In the first sample it is profitably for Apollinaria to make the existing 1 gram of her magic powder to ingredient with the index 2, then Apollinaria will be able to bake 4 cookies.

In the second sample Apollinaria should turn 1 gram of magic powder to ingredient with the index 1 and 1 gram of magic powder to ingredient with the index 3. Then Apollinaria will be able to bake 3 cookies. The remaining 1 gram of the magic powder can be left, because it can't be used to increase the answer

题目大意:每制作一个饼干都需要n种原料,每一种原料都要求有一定数量,每一种原料你都有一些,除此之外,

你还有kg魔力粉,每一g魔力粉都可以转化为任意1g其他原料,问你最多能够做出多少个饼干。

思路分析:假如没有魔力粉,那么最后饼干的数量肯定是由那个相对最少的决定的,类似于短板效应,所以先按g.have/g.need排个序,得到最初的数量

然后再开始用魔力粉补那些不够的原料,若能补全一份,则sum++。不过复杂度很高,但是因为最大n只到1000,所以也过了,后面那一道就没戏了。

待我学完二分再来补

代码:

#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
const int maxn=1000+10;
struct nod
{
    int need;
    int have;
    double t;
};
nod g[maxn];
int a[maxn];
bool cmp(nod x,nod y)
{
    return x.t<y.t;
}
int main()
{
    int n,k,i;
    while(~scanf("%d%d",&n,&k))
    {
        for(i=1;i<=n;i++)
        scanf("%d",&g[i].need);
        for(i=1;i<=n;i++)
        {
        scanf("%d",&g[i].have);
        g[i].t=g[i].have*1.0/g[i].need*1.0;
        }
        sort(g+1,g+n+1,cmp);
        int r=(int)g[1].t;
       // cout<<r<<endl;
        int sum=r;
        //for(int i=1;i<=n;i++)
            //cout<<g[i].have<<" ";
        //cout<<endl;
        for(i=1;i<=n;i++)
        {
            a[i]=g[i].have-r*g[i].need;
           // cout<<a[i]<<" ";
        }
       // cout<<endl;
        while(k>0)
        {
        for(i=1;i<=n;i++)
        {
            if(a[i]<g[i].need)
            {
                int m=g[i].need-a[i];
                if(k>=m)
                {
                    k-=m;
                    a[i]+=m;
                }
                else
                {
                    k==0;
                    break;
                }
            }
        }
        if(i==n+1)
        {
            for(int j=1;j<=n;j++)
            {
                a[j]-=g[j].need;
            }
            sum++;
        }
        else break;
        }
        cout<<sum<<endl;
    }
    return 0;
}

Codeforces Round #350 (Div. 2)A,B,C,D1的更多相关文章

  1. Codeforces Round #350 (Div. 2) A B C D1 D2 水题【D2 【二分+枚举】好题】

    A. Holidays 题意:一个星球 五天工作,两天休息.给你一个1e6的数字n,问你最少和最多休息几天.思路:我居然写成模拟题QAQ. #include<bits/stdc++.h> ...

  2. Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 模拟

    题目链接: http://codeforces.com/contest/670/problem/E 题解: 用STL的list和stack模拟的,没想到跑的还挺快. 代码: #include<i ...

  3. Codeforces Round #350 (Div. 2) D2. Magic Powder - 2

    题目链接: http://codeforces.com/contest/670/problem/D2 题解: 二分答案. #include<iostream> #include<cs ...

  4. Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor (链表)

    题目链接:http://codeforces.com/contest/670/problem/E 给你n长度的括号字符,m个操作,光标初始位置是p,'D'操作表示删除当前光标所在的字符对应的括号字符以 ...

  5. Codeforces Round #350 (Div. 2)解题报告

    codeforces 670A. Holidays 题目链接: http://codeforces.com/contest/670/problem/A 题意: A. Holidays On the p ...

  6. Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 栈 链表

    E. Correct Bracket Sequence Editor 题目连接: http://www.codeforces.com/contest/670/problem/E Description ...

  7. Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分

    D1. Magic Powder - 1 题目连接: http://www.codeforces.com/contest/670/problem/D1 Description This problem ...

  8. Codeforces Round #350 (Div. 2) C. Cinema 水题

    C. Cinema 题目连接: http://www.codeforces.com/contest/670/problem/C Description Moscow is hosting a majo ...

  9. Codeforces Round #350 (Div. 2) B. Game of Robots 水题

    B. Game of Robots 题目连接: http://www.codeforces.com/contest/670/problem/B Description In late autumn e ...

随机推荐

  1. C#邮件发送(最坑爹的邮箱-QQ邮箱)---转发(SmallFlyElephant)

    C#邮件发送(最坑爹的邮箱-QQ邮箱) 最近工作挺清闲的,有空的时候陪妹子出去玩玩,自己看看小说,看看电影,日子过的挺欢乐的,这个星期幡然悔悟,代码才是我的最爱,做点小东西,就写个邮件发送程序.说的邮 ...

  2. jquery1.9学习笔记 之层级选择器(二)

    子孙选择器(“祖先 子孙”) 描述:选择所有给出祖先选择器的子孙选择器. 例子: 用蓝色虚线边框标记所有表单子孙元素的输入.表单里的输入框用黄色背景. <!doctype html>< ...

  3. angular-route 里面templeteUrl 动态加载

    https://segmentfault.com/q/1010000002524964

  4. PHP 文件写入或追加数据

    PHP file_put_contents() 函数是一次性向文件写入字符串或追加字符串内容的最合适选择. file_put_contents() file_put_contents() 函数用于把字 ...

  5. MySQL跨表更新字段 工作记录

    工作中遇到两表查询,从user表中获取用户唯一id字段 写入到另外一张qiuzu表中的uid字段中; 二者可以关联起来的只有用户的手机号码tel字段; 了解需求后数据量稍多,不可能一个一个的手动修改 ...

  6. [工具] 解决sublime text运行javascript console无输出问题

    1.使用nodeJS在sublime text 运行javascript 下载安装nodeJS 在sublime text新建build system:tools->build system-& ...

  7. 了解 Windows Azure 存储的可伸缩性、可用性、持久性和计费

    借助 Windows Azure存储,应用程序开发者及其应用程序和用户可以在云中使用可用性更高.持久性更长.可伸缩性更强的海量存储.开发者可以构建能随时随地高效访问数据的服务,在所需的时间段内存储任意 ...

  8. VS项目如何添加到svn

    SVN是Subversion的简称,是一个开放源代码的版本控制系统,相较于RCS.CVS,它采用了分支管理系统,它的设计目标就是取代CVS.这里就讲一下VS2010如何将项目导入SVN版本控制. 工具 ...

  9. requirejs-define jquery 快速初学实例(一)

    原文地址:http://6yang.net/articles_view.php?id=1103 2011-10-18 13:12:01 by [6yang], 1029 visits, 收藏 | 返回 ...

  10. linux下 tags相关

    在vim中配置好了YouCompleteMe插件,发现把光标移动到函数名下再按ctrl+],并不能跳转到该函数的定义处.解决办法: 1.先查看有没有安装ctags,运行ctags –version查看 ...