2020-2-13赛

 

问题 F: Escaping the Farm

时间限制: 1 Sec  内存限制: 64 MB
[提交] [状态]

题目描述

The cows have decided on a daring plan to escape from the clutches of Farmer John.  They have managed to procure a small inflatable raft, and during the cover of night, a group of cows will board the raft and row across the river bordering the farm.  The plan seems perfect, until the cows realize that their small inflatable raft may not be able to hold much weight!

The N cows (1 <= N <= 20) have weights w_1 ... w_N.  To figure out if a group of cows is light enough to avoid sinking the raft, the cows add up  all of the weights in the group.  Unfortunately, cows are notoriously bad at arithmetic, and if the addition of the weights of the cows in a group causes any carries to occur (using standard base 10 addition), then the cows give up and conclude that group must weigh too much to use the raft. Any group whose weights can be added without any carries is assumed to be light enough to fit on the raft.  

Please help the cows determine the size of the largest group that they believe can fit on the raft (that is, the largest group whose weights can be added together with no carries).
 

输入

* Line 1: The number of cows, N (1 <= N <= 20).
* Lines 2..N+1: Each line contains the weight of one cow, an integer in the range 1...100,000,000.

输出

* Line 1: The number of cows in the largest group whose weights can be added together with no carries.

样例输入 Copy

5
522
6
84
7311
19

样例输出 Copy

3

提示

There are 5 cows, with weights 522, 6, 84, 7311, and 19.The three weights 522, 6, and 7311, can be added together with no carries:
   522
     6
+ 7311
------
  7839

 

题目大意:使其没有进位的最大数目,

//超时代码
#include <bits/stdc++.h>
using namespace std;
const int mod=2e5+5;
typedef long long ll;
int A[105],vis[105],ans,n;
void dfs(int st,int sum,int k)
{
   if(k>ans) ans=k;
   if(ans>n) return ;
    else
    {
    for(int i=st;i<=n;i++)
    {
        if(vis[i]) continue;
        else
        {
            int a=sum,b=A[i],flag=1;
            while(a&&b)
            {
                int x=a%10,y=b%10;
                if(x+y>9)
                {
                    flag=0;
                    break;
                }
                 a/=10;b/=10;
            }
            if(flag)
            {
                vis[i]=1;
                dfs(st+1,sum+A[i],k+1);
                vis[i]=0;
            }
 
 
        }
    }
    }
}
int main()
{
  scanf("%d",&n);
  for(int i=1;i<=n;i++)
  {
      scanf("%d",&A[i]);
  }
  dfs(1,0,0);
  printf("%d",ans);
    return 0;
}
 

 

 

#include <bits/stdc++.h>
using namespace std;
const int mod=2e5+5;
typedef long long ll;
int A[105],ans,n;
void dfs(int st,int sum,int k)
{
   if(k>ans) ans=k;
   if(ans>n) return ;
    else
    {
    for(int i=st;i<=n;i++)
    {
            int a=sum,b=A[i],flag=1;
            while(a&&b)
            {
                int x=a%10,y=b%10;
                if(x+y>9)
                {
                    flag=0;
                    break;
                }
                 a/=10;b/=10;
            }
            if(flag)
            {
                dfs(i+1,sum+A[i],k+1);
            }
    }
    }
}
int main()
{
  scanf("%d",&n);
  for(int i=1;i<=n;i++)
  {
      scanf("%d",&A[i]);
  }
  for(int i=1;i<=n;i++)
      dfs(i+1,A[i],1);
  printf("%d",ans);
    return 0;
}
 
/**************************************************************
    Problem: 2556
    User: 2019UPC110
    Language: C++
    Result: 正确
    Time:39 ms
    Memory:2024 kb
****************************************************************/

 

 

问题 K: Powerful Discount Tickets

时间限制: 1 Sec  内存限制: 128 MB
[提交] [状态]

题目描述

Takahashi is going to buy N items one by one.
The price of the i-th item he buys is Ai yen (the currency of Japan).
He has M discount tickets, and he can use any number of them when buying an item.
If Y tickets are used when buying an item priced X yen, he can get the item for X/2Y (rounded down to the nearest integer) yen.
What is the minimum amount of money required to buy all the items?

Constraints
·All values in input are integers.
·1≤N,M≤105
·1≤Ai≤109

输入

Input is given from Standard Input in the following format:

N M
A1 A2 ... AN

输出

Print the minimum amount of money required to buy all the items.

样例输入 Copy

【样例1】
3 3
2 13 8
【样例2】
4 4
1 9 3 5
【样例3】
1 100000
1000000000
【样例4】
10 1
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

样例输出 Copy

【样例1】
9
【样例2】
6
【样例3】
0
【样例4】
9500000000

提示

样例1解释
We can buy all the items for 9 yen, as follows:
Buy the 1-st item for 2 yen without tickets.
Buy the 2-nd item for 3 yen with 2 tickets.
Buy the 3-rd item for 4 yen with 1 ticket.
样例3解释
We can buy the item priced 1000000000 yen for 0 yen with 100000 tickets.

 

优先队列

#include <bits/stdc++.h>
using namespace std;
const int mod=1e5+5;
typedef long long ll;
priority_queue<int>q;
int main()
{
   int n,m;
   scanf("%d %d",&n,&m);
   for(int i=1;i<=n;i++)
   {
       int a;
       scanf("%d",&a);
       q.push(a);
   }
   //sort(A+1,A+1+n,cmp);
   while(m)
  {
    int temp=q.top()/2;
    q.pop();
    q.push(temp);
    m--;
   }
   ll ans=0;
   while(!q.empty())
   {
       ans+=q.top();
       q.pop();
   }
   printf("%lld",ans);
    return 0;
}
 
/**************************************************************
    Problem: 14557
    User: 2019UPC110
    Language: C++
    Result: 正确
    Time:214 ms
    Memory:2880 kb
****************************************************************/

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值