noip模拟测试 远征

4134: [NOIP2016模拟赛No.6]远征

时间限制: 1 Sec  内存限制: 128 MB
提交: 54  解决: 32
[提交][状态][讨论版]

题目描述

寒枫将军将要带领他的部队去圣雪山消灭那里的冰龙。

部队分成了若干个小队,属于同一个小队的人兵种相同。寒枫将军有着杰出的指挥能力,在战斗的时候,寒枫将军能够让所有相同兵种的人互相配合,使t个相同兵种的人发挥出t2的战斗力;寒枫将军还能让不同兵种的人互相配合,使整个部队的战斗力是所有兵种战斗力的和。

例如,部队中有3个小队,分别是5个人的步兵小队,3个人的步兵小队,3个人的骑兵小队。那么步兵战斗力为64,骑兵战斗力为9,部队总战斗力为73。

寒枫将军需要知道他的部队的战斗力是多少。

 

输入

第一行一个整数n,表示小队数。接下来n行,第i行有两个整数ai、bi,表示这个小队有ai个人,兵种为bi。

输出

一行一个整数,部队的战斗力。

样例输入

3
5 1
3 1
3 2

样例输出

73

提示


10%的数据,n=1

 


30%的数据,n≤1000

 


另有20%的数据,ai=1

 


另有30%的数据,bi≤1000



100%的数据,1≤n≤100000,1≤ai≤10000,1≤bi≤1,000,000,000

 

开一个结构体存一下每个军队的信息,然后排序,然后暴力扫就行。

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstdio>
 4 #include <cstring>
 5 #include <cstdlib>
 6 
 7 using namespace std;
 8 
 9 #define FILE_NAME "expedition"
10 
11 int n;
12 long long local, tot, ans;
13 
14 struct GROUP{
15     long long a, b;
16     bool operator < (GROUP y) const{
17         return b < y.b;
18     }
19 }grp[100010];
20 
21 int main(){
22     freopen(FILE_NAME ".in", "r", stdin);
23     freopen(FILE_NAME ".out", "w", stdout);
24     scanf("%d", &n);
25     for(int i = 1 ; i <= n ; i ++){
26         scanf("%lld%lld", &grp[i].a, &grp[i].b);
27     }
28     sort(grp + 1, grp + 1 + n);
29 //    for(int i = 1 ; i <= n ; i ++)printf("%lld %lld\n", grp[i].a, grp[i].b);
30     for(int i = 1 ; i <= n + 1 ; i ++){
31         if(grp[i].b != local){
32             ans += tot * tot;
33             local = grp[i].b;
34             tot = grp[i].a;
35         }else{
36             tot += grp[i].a;
37         }
38     }
39     printf("%lld\n", ans);
40     return 0;
41 }
View Code

 

posted @ 2017-08-08 15:16  KingSann  阅读(220)  评论(0编辑  收藏  举报