URAL1964:Chinese Dialects

Vova moved from Guangzhou to Shenzhen. He immediately found out that the local people don‘t understand his Cantonese phrases as well. Vova tried chatting with them in Mandarin, but to no success.

Then Vova decided to learn more about Chinese dialects. It turned out that people in China speak kdifferent dialects, at that at least a1 people
speak the first dialect, at least a2 people speak the second dialect, …, at least ak people
speak the k-th dialect. How many people speak all k dialects if the population of China is n people?

Input

The first line contains integers n and k (2 ≤ k ≤ 20; 1 ≤ n ≤ 109). The second line contains
space-separated integers a1, …, ak (1 ≤ ak ≤ n).

Output

Print the minimum number of people in China that speak all k dialects of the Chinese language.

Samples

input output
1000000000 2
800000000 800000000
600000000
1000000000 2
500000000 500000000
0

题意:有n个人,有m种语言,然后m个输入代表每种语言有几个人会讲,要求会讲所有语言的人有几个

思路:对于两种语言的话,我们不难发现必然是a1+a2-n,那么我们以此类推,先求出会讲两种语言的人数,在把会讲两种语言的人看做一种,循环计算下去求得会讲所有语言的人有几个

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;
#define ls 2*i
#define rs 2*i+1
#define up(i,x,y) for(i=x;i<=y;i++)
#define down(i,x,y) for(i=x;i>=y;i--)
#define mem(a,x) memset(a,x,sizeof(a))
#define w(a) while(a)
#define LL long long
const double pi = acos(-1.0);
#define Len 200005
#define mod 19999997
const int INF = 0x3f3f3f3f;

LL n,m,N,M;

int main()
{
    w(~scanf("%I64d%I64d",&n,&m))
    {
        LL t = n,x;
        w(m--)
        {
            scanf("%I64d",&x);
            t = max(0LL,t+x-n);
        }
        printf("%I64d\n",t);
    }

    return 0;
}
时间: 2024-10-17 10:34:43

URAL1964:Chinese Dialects的相关文章

IEF could not decode Chinese character in IE history well

My friend is working on some case, and she looks not in the mood. I ask her what's going on. She wants me to look at the screenshot as below. That's why she is upset...IEF could not decode Chinese character in IE history well, so the filenames in Chi

This weekend, I think of changing my article and diary language when using computers from Chinese to English.

It was really a pity of the fact that thinking things in Chinese when being companion with these foreign invented machines which originally works with English. So,just to improve efficiency, I may have to make this change. Just because this language

URAL1962:In Chinese Restaurant(并查集)

When Vova arrived in Guangzhou, his Chinese friends immediately invited him to a restaurant. Overalln people came to the restaurant, including Vova. The waiter offered to seat the whole company at a traditional large round table with a rotating dish

Atitit.404错误解决标准流程and url汉字中文路径404错误resin4 resin chinese char path 404 err解决

Atitit.404错误解决标准流程and url汉字中文路径404错误resin4 resin chinese char path 404 err解决 1. #原因解析 1 2. #解决方式 2 3. 输出图片流... 2 4. --code 2 5. 参考 3 1. #原因解析 查看累挂发送d url,,,俄使用的是ff..它把url转换成个 http://localhost/img/QQ%E6%88%AA%E5%9B%BE20140401175433.jpg 发送出去..每汉字3个%字符,

AS1 A Chinese Girls&#39; Amusement

题意:给你一个大数 ,问你求小于这个数一半且与他互质的数. 解题思路:奇数直接是二分之一,偶数小于它一半的那个最大奇数. 解题代码: 1 // File Name: a.cpp 2 // Author: darkdream 3 // Created Time: 2015年03月21日 星期六 23时08分24秒 4 5 #include<vector> 6 #include<list> 7 #include<map> 8 #include<set> 9 #i

SGU 193.Chinese Girls&#39; Amusement

/* 实际上就是求一个k,满足k<=n/2,且gcd(n,k)=1 如果n为奇数,k为[n/2] 如果n为偶数,k=n/2-1-(n/2)%2 */ #include <iostream> using namespace std; string s; void div2() { string t; int l = s.size() - 1, tem = s[0] - '0'; if (tem > 1) t += '0' + tem / 2; tem &= 1; for (i

chrome tab and bookmark display chinese font crash

ubuntu chrome tab and bookmark display chinese font crash reinstall chinese font with below command: $ sudo apt-get install ttf-wqy-microhei ttf-wqy-zenhei xfonts-wqy chrome tab and bookmark display chinese font crash,布布扣,bubuko.com

uva 10710 - Chinese Shuffle(完美洗牌)

题目链接:uva 10710 - Chinese Shuffle 题目大意:给出n张牌,按照顺序排列好,进行n-1次完美洗牌,问是否可以变成原来德序列. 解题思路:根据完美洗牌的性质,于是第x张牌经过p次后德位置有x?2p,于是只需要证明第1张牌最后是否在远处即可. #include <cstdio> #include <cstring> typedef long long ll; ll pow_mod(ll a, ll n, ll mod) { ll ans = 1; while

10710 - Chinese Shuffle(数论+完美洗牌)

UVA 10710 - Chinese Shuffle 题目链接 题意:给定n张牌,完美洗牌n - 1次,问是否会变回原来的序列 思路:完美洗牌: 假设有a1a2a3...anb1b2b3...bn的牌,设每张牌原来的位置为x,那么完美洗牌一次后,前n张牌分别到2 x位置,后n张分别到1, 3, 5..也就是2 x % (2 n + 1)的位置,因此每张牌位置变为2 x % (2 * n + 1).这样去判断每张牌是否到原位就可以得出答案了,但是牌很多的情况根本无法判断,那怎么办呢? 其实只要判