2014 Multi-University Training Contest 1

Couple doubi

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 674    Accepted Submission(s): 483


Problem Description
DouBiXp has a girlfriend named DouBiNan.One day they felt very boring and decided to play some games. The rule of this game is as following. There are k balls on the desk. Every ball has a value and the value of ith (i=1,2,...,k) ball is 1^i+2^i+...+(p-1)^i (mod p). Number p is a prime number that is chosen by DouBiXp and his girlfriend. And then they take balls in turn and DouBiNan first. After all the balls are token, they compare the sum of values with the other ,and the person who get larger sum will win the game. You should print “YES” if DouBiNan will win the game. Otherwise you should print “NO”.
 

Input
Multiply Test Cases. 
In the first line there are two Integers k and p(1<k,p<2^31).
 

Output
For each line, output an integer, as described above.
 

Sample Input
  
  
2 3 20 3
 

Sample Output
  
  
YES NO
 

Author
FZU
 

Source
 

//0MS	228K
#include<stdio.h>
int main()
{
    int k,p;
    while(scanf("%d%d",&k,&p)!=EOF)
    {
        if(k/(p-1)&1)printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}


Task

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2484    Accepted Submission(s): 636


Problem Description
Today the company has m tasks to complete. The ith task need xi minutes to complete. Meanwhile, this task has a difficulty level yi. The machine whose level below this task’s level yi cannot complete this task. If the company completes this task, they will get (500*xi+2*yi) dollars.
The company has n machines. Each machine has a maximum working time and a level. If the time for the task is more than the maximum working time of the machine, the machine can not complete this task. Each machine can only complete a task one day. Each task can only be completed by one machine.
The company hopes to maximize the number of the tasks which they can complete today. If there are multiple solutions, they hopes to make the money maximum.
 

Input
The input contains several test cases. 
The first line contains two integers N and M. N is the number of the machines.M is the number of tasks(1 < =N <= 100000,1<=M<=100000).
The following N lines each contains two integers xi(0<xi<1440),yi(0=<yi<=100).xi is the maximum time the machine can work.yi is the level of the machine.
The following M lines each contains two integers xi(0<xi<1440),yi(0=<yi<=100).xi is the time we need to complete the task.yi is the level of the task.
 

Output
For each test case, output two integers, the maximum number of the tasks which the company can complete today and the money they will get.
 

Sample Input
   
   
1 2 100 3 100 2 100 1
 

Sample Output
   
   
1 50004
 

Author
FZU
 

Source
 
费用流果断TLE,还得贪心。
要求能够完成的任务最多,并且获得的奖励最多。那么对于每一个任务,要找到所有能够完成此任务的机器,从这些机器当中选择等级最小的来执行此任务。如果暴力找的话,时间复杂度是O(m*n),还会超时,因为等级最大是100,所以对此稍加处理,就可以大大的降低时间复杂度了。
//218MS	2228K
#include<stdio.h>
#include<algorithm>
#include<string.h>
#define M 100007
using namespace std;
int vis[M];
struct sa
{
    int time,leve;
}task[M],machine[M];
int cmp(sa a,sa b)
{
    if(a.time==b.time)return a.leve>b.leve;
    return a.time>b.time;
}
int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        memset(vis,0,sizeof(vis));
    for(int i=0;i<n;i++)
        scanf("%d%d",&machine[i].time,&machine[i].leve);
    for(int i=0;i<m;i++)
        scanf("%d%d",&task[i].time,&task[i].leve);
    sort(machine,machine+n,cmp);
    sort(task,task+m,cmp);
    long long ans=0;
    int count=0;
    for(int i=0,j=0;i<m;i++)
    {
        while(j<n&&machine[j].time>=task[i].time)
        {
            vis[machine[j].leve]++;
            j++;
        }
        for(int k=task[i].leve;k<=100;k++)
            if(vis[k])
            {
                vis[k]--;
                count++;
                ans+=(task[i].time*500+task[i].leve*2);
                break;
            }
    }
    printf("%d %I64d\n",count,ans);
    }
    return 0;
}


Turn the pokers

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 999    Accepted Submission(s): 372


Problem Description
During summer vacation,Alice stay at home for a long time, with nothing to do. She went out and bought m pokers, tending to play poker. But she hated the traditional gameplay. She wants to change. She puts these pokers face down, she decided to flip poker n times, and each time she can flip Xi pokers. She wanted to know how many the results does she get. Can you help her solve this problem?
 

Input
The input consists of multiple test cases. 
Each test case begins with a line containing two non-negative integers n and m(0<n,m<=100000). 
The next line contains n integers Xi(0<=Xi<=m).
 

Output
Output the required answer modulo 1000000009 for each test case, one per line.
 

Sample Input
   
   
3 4 3 2 3 3 3 3 2 3
 

Sample Output
   
   
8 3
Hint
For the second example: 0 express face down,1 express face up Initial state 000 The first result:000->111->001->110 The second result:000->111->100->011 The third result:000->111->010->101 So, there are three kinds of results(110,011,101)
 

Author
FZU
 

Source
 

设牌的背面为0,正面为1.通过翻转,最后 正面的张数一定为一些间隔为2的连续的一些数。最后的答案就是ans=∑C(m,k),k的取值在最少1的个数和最多1的个数之间。最后答案ans=∑C(m,k)(i<=k<=j&&k%2==i%2),因为除法取模,所以要去逆元。
//421MS	1012K
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<map>
#include<stack>
#include<queue>
#include<vector>

#pragma comment(linker, "/STACK:1024000000");
#define M 100007
#define inf 0x3f3f3f3f
#define ll long long
#define mod 1000000009
#define eps (1e-8)
using namespace std;
int n,m;
ll f[M]={1,1};
void init()
{
    for(ll i=2;i<M;i++)
        f[i]=(i*f[i-1])%mod;
}
ll quick_mod(ll a,ll b,ll m)//a^b%m
{
    long long ans=1;
    a%=m;
    while(b)
    {
        if(b&1)ans=ans*a%m;
        b>>=1;
        a=a*a%m;
    }
    return ans;
}
int main()
{
  init();
  while(scanf("%d%d",&n,&m)!=EOF)
  {
      int minn,maxx,x,l=0,r=0;
      for(int i=1;i<=n;i++)
      {
          scanf("%d",&x);
          if(l>=x)minn=l-x;
          else if(r>=x)minn=((x&1)==(l&1))?0:1;
          else minn=x-r;

          if(x+r<=m)maxx=r+x;
          else if(l+x<=m)maxx=(((l+x)&1)==(m&1))?m:m-1;
          else maxx=2*m-(x+l);

          l=minn,r=maxx;
      }
      ll ans=0;
      for(int i=l;i<=r;i+=2)
      {
          ll a=f[m];
          ll b=f[m-i]*f[i]%mod;
          ans=(ans+a*quick_mod(b,mod-2,mod)%mod)%mod;
      }
      printf("%I64d\n",ans);
  }
  return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值