URAL 1991. The battle near the swamp

1991. The battle near the swamp

Time limit: 1.0 second

Memory limit: 64 MB

Gungan: Jar Jar, usen da booma!

Jar Jar: What? Mesa no have a booma!

Gungan: Here. Taken dis one.

In the battle with the Trade Federation, Queen Amidala decided to ask gungans for help. Jar Jar Binks escorted the Queen and her people to the holy place where they had an agreement. The gungans agreed
to provide their army in order to get the droids of the Federation out from the capital. The gungan ruler Boss Nass was so grateful for uniting the nations that he appointed Jar Jar a general.

And here they are: two armies lined up along the bank of the swamp. The droids of the Federation are well-disciplined soldiers. They stand in neat formation, divided into n blocks of k droids
each. The gungans have a foolproof weapon against droids, which is small energy balls called boom booms. One such ball can disable exactly one droid.

Jar Jar Binks also decided to split his army into n parts and give each part a task to destroy the corresponding block of droids. Each part received a truck with boom booms. Now help general
Binks calculate the number of boom booms that will be left unused and the number of droids that will survive the attack. You can assume that when a boom boom is fired at a droid by a gungan, it always hits the target.

Input

The first line of the input contains numbers n and k (1 ≤ nk ≤ 10 000). The second line containsn numbers ai (0 ≤ ai ≤ 100 000) —
the number of boom-booms in the i-th truck.

Output

Print two integers — the number of unused boom booms and the number of survived droids.

Sample

input output
4 5
2 7 5 0
2 8

题意:n支军队,每个军队ai个士兵,每个士兵能消灭一个敌人。每支军队要去的地方有k个敌人,问总共有多少士兵没用到,有多少敌人没被消灭。

解析:多出来的就是没用到的,不够的就是逃脱的敌人。

AC代码:

#include <cstdio>

int main(){
    int n, k, ans, anss, foo;
    while(scanf("%d%d", &n, &k)==2){
        ans = anss = 0;
        while(n--){
            scanf("%d", &foo);
            if(foo > k) ans += foo - k;
            else anss += k - foo;
        }
        printf("%d %d\n", ans, anss);
    }
    return 0;
}
时间: 2024-11-05 06:14:10

URAL 1991. The battle near the swamp的相关文章

(校赛)URAL 1991 The battle near the swamp

In the battle with the Trade Federation, Queen Amidala decided to ask gungans for help. Jar Jar Binks escorted the Queen and her people to the holy place where they had an agreement. The gungans agreed to provide their army in order to get the droids

2013-2014 ACM-ICPC, NEERC, Eastern Subregional Contest PART (7/10)

\[2013-2014\ ACM-ICPC,\ NEERC,\ Eastern\ Subregional\ Contest\] \(A.Podracing\) \(B.The\ battle\ near\ the\ swamp\) 签到 //#pragma comment(linker, "/STACK:1024000000,1024000000") #include<bits/stdc++.h> using namespace std; function<void(

URAL 1933 Guns for Battle!

给一个n,要求构造一个矩阵,满足: 1.矩阵大小为(2n+1)*(2n+1) 2.沿对角线对称 3.每个数的值在[0,2n+1]上 4.每行每列没有重复的值 手动写了一下 直接找到规律.. #include<cstdio> #include<cstring> using namespace std; int n,m,i,j,cnt,s[205][205],k; int main() { while(~scanf("%d",&n)) { m=2*n+1;

URAL 1439. Battle with You-Know-Who treap树

题目来源:URAL 1439. Battle with You-Know-Who 题意:开始有数列1, 2, 3, ... L k输出第k大的数 D k删除第k大的数 思路:treap树插入删除的数 每次二分查找第k大的数为mid 查询treap小于等于mid的数有y个 那么mid应该是第mid-y大的数 与k比较 继续二分 #include <cstdio> #include <cstring> #include <cstdlib> #include <algo

URAL - 1785,1293,1877,1409,1820,1787,1264,2012

开始水URAL,今天先来几个.. 1785. Lost in Localization Time limit: 1.0 second Memory limit: 64 MB The Lavin Interactive Company, which has developed the turn-based strategy Losers-V, is constantly extending its target market by localizing the game to as many la

URAL 1873. GOV Chronicles

唔 神题一道 大家感受一下 1873. GOV Chronicles Time limit: 0.5 secondMemory limit: 64 MB A chilly autumn night. Well wrapped up in a coat, a man is rapidly walking along a gray street. This is the Tradition Keeper of the ACM club in Ural State University. Drizzl

NYOJ 284 坦克大战 &amp;&amp; POJ 2312 Battle City (广搜+优先队列)

链接:click here~~ 题意: 描述 Many of us had played the game "Battle city" in our childhood, and some people (like me) even often play it on computer now. What we are discussing is a simple edition of this game. Given a map that consists of empty space

Ural 1081 Binary Lexicographic Sequence(DP)

题目地址:Ural 1081 先用dp求出每个长度下的合法序列(开头为1)的个数.然后求前缀和.会发现正好是一个斐波那契数列.然后每次判断是否大于此时长度下的最少个数,若大于,说明这一位肯定是1,若小于,则肯定是0.就这样不断输出出来即可. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #in

URAL 1684. Jack&#39;s Last Word KMP

题目来源:URAL 1684. Jack's Last Word 题意:输入a b 把b分成若干段 每一段都是a的前缀 思路:b为主串 然后用a匹配b 记录到b的i位置最大匹配的长度 然后分割 分割的时候要从后往前 如果a = abac b = abab 那么如果从前往后 首先覆盖了aba 然后b就不能覆盖了 从后往前就可以了 首先覆盖ab 下一次还是ab 因为已经记录了到i位置的最大匹配长度 根据长度从末尾倒退 每次倒退的时候只要是最大的匹配的长度 因为如果在某一次的递推 记录的最大匹配的前缀