码迷,mamicode.com
首页 > 其他好文 > 详细

NowCoder牛客练习赛7-A.骰子的游戏 B.购物-优先队列

时间:2017-12-02 15:05:36      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:ext   ant   n+1   数据   东方   cout   ati   important   scan   

A.骰?的游戏

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32768K,其他语言65536K
64bit IO Format: %lld

 

题目描述

在Alice和Bob面前的是两个骰子,上面分别写了六个数字。

Alice和Bob轮流丢掷骰子,Alice选择第一个骰子,而Bob选择第二个,如果谁投掷出的数更大,谁就可以获胜。

现在给定这两个骰子上的6个数字,你需要回答是Alice获胜几率更大,还是Bob获胜几率更大。(请注意获胜几率相同的情况)

 

输入描述:

第一行一个数T,表示数据个数。
接下来的每一组数据一共有2行,每一行有6个正整数,第一行是第一个骰子上的6个数,第二行是第二个骰子上的6个数。

输出描述:

如果Alice获胜几率更大,你需要输出Alice;
如果Bob获胜几率更大,你需要输出Bob;
如果获胜几率一样大,你需要输出Tie。
示例1

输入

2
3 3 3 3 3 3
1 1 4 4 4 4
1 2 3 4 5 6
6 5 4 3 2 1

输出

Bob
Tie

说明

第一个数据中,Alice有三分之一几率获胜,Bob有三分之二几率获胜;
第二个数据中,Alice和Bob的骰子完全一致,所以获胜几率一样大。

备注:

对于30%的数据,1 ≤ T ≤ 10。

对于60%的数据,1 ≤ T ≤ 1000。

对于100%的数据,1 ≤ T ≤ 105,所有输入的数均 ≤ 107

代码:

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<algorithm>
 5 #include<cmath>
 6 using namespace std;
 7 typedef long long ll;
 8 int a[10],b[10];
 9 int main(){
10     int t;
11     scanf("%d",&t);
12         while(t--){
13             for(int i=0;i<6;i++)
14                 scanf("%d",&a[i]);
15             for(int i=0;i<6;i++)
16                 scanf("%d",&b[i]);
17             int num=0,cnt=0;
18             for(int i=0;i<6;i++){
19                 for(int j=0;j<6;j++){
20                 if(a[i]>b[j])num++;
21                 if(a[i]<b[j])cnt++;
22                 }
23             }
24             if(num>cnt)printf("Alice\n");
25             else if(num<cnt)printf("Bob\n");
26             else printf("Tie\n");
27         }
28     return 0;
29 }

 

B.购物

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32768K,其他语言65536K
64bit IO Format: %lld

 

题目描述

在遥远的东方,有一家糖果专卖店
这家糖果店将会在每天出售一些糖果,它每天都会生产出m个糖果,第i天的第j个糖果价格为C[i][j]元
现在的你想要在接下来的n天去糖果店进行选购,你每天可以买多个糖果,也可以选择不买糖果,但是最多买m个。(因为最多只生产m个)买来糖果以后,你可以选择吃掉糖果或者留着之后再吃。糖果不会过期,你需要保证这n天中每天你都能吃到至少一个糖果。
这家店的老板看你经常去光顾这家店,感到非常生气。(因为他不能好好睡觉了)于是他会额外的要求你支付点钱。具体来说,你在某一天购买了 k 个糖果,那么你在这一天需要额外支付 k2 的费用。

那么问题来了,你最少需要多少钱才能达成自己的目的呢?

输入描述:

第一行两个正整数n和m,分别表示天数以及糖果店每天生产的糖果数量。
接下来n行(第2行到第n+1行),每行m个正整数,第x+1行的第y个正整数表示第x天的第y个糖果的费用。

输出描述:

输出只有一个正整数,表示你需要支付的最小费用。
示例1

输入

3 2 
1 1
100 100 
10000 10000

输出

107
示例2

输入

5 5
1 2 3 4 5
2 3 4 5 1 
3 4 5 1 2 
4 5 1 2 3 
5 1 2 3 4

输出

10

备注:

对于100%的数据,1 ≤ n, m ≤ 300 , 所有输入的数均 ≤ 10^6。
代码:
 1 #include<cstring>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<cmath>
 5 #include<iostream>
 6 #include<queue>
 7 using namespace std;
 8 typedef long long ll;
 9 const int N=1e4+10;
10 int a[N][N];
11 priority_queue<int,vector<int>,greater<int> >gg;
12 int main(){
13     int n,m;
14     ll ans;
15     while(cin>>n>>m){
16         for(int i=1;i<=n;i++)
17             for(int j=1;j<=m;j++)
18             cin>>a[i][j];
19         for(int i=1;i<=n;i++)
20             sort(a[i]+1,a[i]+1+m);
21         for(int i=1;i<=n;i++){
22             int cnt=1;
23             for(int j=1;j<=m;j++){
24                 a[i][j]+=cnt;
25                 cnt+=2;
26             }
27         }
28         ans=0;
29         for(int j=1;j<=m;j++)
30             gg.push(a[1][j]);
31         ans+=gg.top();
32         gg.pop();
33         for(int i=2;i<=n;i++){
34             for(int j=1;j<=m;j++)
35                 gg.push(a[i][j]);
36             ans+=gg.top();
37             gg.pop();
38         }
39         cout<<ans;
40     }
41     return 0;
42 }

一开始二维数组排序的通过了90%的数据,应该是卡在一组很大的数上了。

贴一下差点通过的代码。。。

 1 wa90%d的数据,应该是卡在一组很大的数上了。
 2 #include<iostream>
 3 #include<cstring>
 4 #include<cstdio>
 5 #include<algorithm>
 6 #include<cmath>
 7 using namespace std;
 8 typedef long long ll;
 9 const int N=2e4+1000;
10 const int maxn=1e7+10;
11 const int INF=0x3f3f3f3f;
12 int a[N][N],b[maxn];
13 int main(){
14     int n,m;
15     ll ans;
16     while(~scanf("%d%d",&n,&m)){
17         for(int i=1;i<=n;i++)
18         for(int j=1;j<=m;j++)
19             scanf("%d",&a[i][j]);
20         for(int i=1;i<=n;i++)
21             sort(a[i]+1,a[i]+1+m);
22         for(int i=1;i<=n;i++){
23                 int cnt=1;
24             for(int j=1;j<=m;j++){
25                 a[i][j]+=cnt;
26                 cnt+=2;
27             }
28         }
29         ans=0;
30         sort(a[1]+1,a[1]+m);
31         ans+=a[1][1];
32         a[1][1]=INF;
33         int h=0;
34         for(int i=1;i<=n;i++)
35             for(int j=1;j<=m;j++)
36                 b[h++]=a[i][j];
37         sort(b,b+h);
38         //for(int i=0;i<h;i++)
39         //printf("%d ",b[i]);
40         for(int i=0;i<n-1;i++)
41             ans+=b[i];
42         printf("%lld\n",ans);
43     }
44     return 0;
45 }

溜啦溜啦,还有一道珂朵莉的数列的树状数组+大数(高精度)没写出来,补题补题。

NowCoder牛客练习赛7-A.骰子的游戏 B.购物-优先队列

标签:ext   ant   n+1   数据   东方   cout   ati   important   scan   

原文地址:http://www.cnblogs.com/ZERO-/p/7954163.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!