BestCoder Round #58 (div.2) A B C

Card Game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 254    Accepted Submission(s): 197


Problem Description
Soda and Beta are good friends. They are going to play a card game today. Soda has n cards with number a1,a2,...,an while Beta has n cards with number b1,b2,...,bn .

First, they choose a number m no larger than n . Then they both randomly select m cards from their own n cards. The one with larger sum of the selected cards will win. Soda wants to know if he can always win no mater what cards will be randomly selected from him and Beta.
 

Input
There are multiple test cases. The first line of input contains an integer T(1T100) , indicating the number of test cases. For each test case:

The first line contains two integer n and m (1mn500) . The second line contains n integers a1,a2,...,an (1ai1000) denoting Soda's cards. The third line contains n integers b1,b2,...,bn (1bi1000) denoting Beta's cards.
 

Output
For each test case, output "YES" (without the quotes) if Soda can always win, otherwise output "NO" (without the quotes) in a single line.
 

Sample Input
  
  
2 3 1 4 5 6 1 2 3 5 2 3 4 7 8 9 3 4 5 2 3
 

Sample Output
  
  
YES NO
 

Source
 

Recommend
hujie   |   We have carefully selected several similar problems for you:   5498  5497  5490  5489  5488 

 


水题。第一个人取最小,第二个人取最大,判断一下就好。

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int a[1005];
        int b[1005];
        int n,m;
        cin>>n>>m;
        for(int i=0; i<n; i++)
            cin>>a[i];
        for(int i=0; i<n; i++)
            cin>>b[i];
        sort(a,a+n);
        sort(b,b+n);
        int ans1=0;
        int ans2=0;
        for(int i=0; i<m; i++)
            ans1+=a[i];
        for(int i=n-1; m>0; m--,i--)
            ans2+=b[i];
        if(ans1>ans2)
            puts("YES");
        else
            puts("NO");
    }
    return 0;
}




LCS

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 503    Accepted Submission(s): 272


Problem Description
You are given two sequence {a1,a2,...,an} and {b1,b2,...,bn} . Both sequences are permutation of {1,2,...,n} . You are going to find another permutation {p1,p2,...,pn} such that the length of LCS (longest common subsequence) of {ap1,ap2,...,apn} and {bp1,bp2,...,bpn} is maximum.
 

Input
There are multiple test cases. The first line of input contains an integer T , indicating the number of test cases. For each test case:

The first line contains an integer n(1n105) - the length of the permutation. The second line contains n integers a1,a2,...,an . The third line contains n integers b1,b2,...,bn .

The sum of n in the test cases will not exceed 2×106 .
 

Output
For each test case, output the maximum length of LCS.
 

Sample Input
  
  
2 3 1 2 3 3 2 1 6 1 5 3 2 6 4 3 6 2 4 5 1
 

Sample Output
  
  
2 4
 

Source
 

Recommend
hujie   |   We have carefully selected several similar problems for you:   5498  5497  5490  5489  5488 



求出环的个数,只要长度大于2  。n就减一

#include<bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include  <cmath>
using namespace std;
#define inf 0x7f7f7f
int a[100005];
int b[100005];
int c[100005];
int vis[100005];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        int i;
        scanf("%d",&n);
        memset(c,0,sizeof(c));
        memset(vis,0,sizeof(vis));
        for(i=0; i<n; i++)
            scanf("%d",&a[i]);
        for(i=0; i<n; i++)
        {
            scanf("%d",&b[i]);
            c[b[i]]=i;
        }
        int ans=0;
        for(i=0; i<n; i++)
        {
            if(!vis[i])
            {
                int now=i;
                int len=0;
                while(!vis[now])
                {
                    vis[now]=1;
                    now=c[a[now]];
                    len++;
                }
                if(len>1)
                    ans++;
            }
        }
        printf("%d\n",n-ans);
    }
    return 0;
}




Beauty of Sequence

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 550    Accepted Submission(s): 249


Problem Description

Sequence is beautiful and the beauty of an integer sequence is defined as follows: removes all but the first element from every consecutive group of equivalent elements of the sequence (i.e. unique function in C++ STL) and the summation of rest integers is the beauty of the sequence.

Now you are given a sequence A of n integers {a1,a2,...,an} . You need find the summation of the beauty of all the sub-sequence of A . As the answer may be very large, print it modulo 109+7 .

Note: In mathematics, a sub-sequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example {1,3,2} is a sub-sequence of {1,4,3,5,2,1} .

 


Input

There are multiple test cases. The first line of input contains an integer T , indicating the number of test cases. For each test case:

The first line contains an integer n (1n105) , indicating the size of the sequence. The following line contains n integers a1,a2,...,an , denoting the sequence (1ai109) .

The sum of values n for all the test cases does not exceed 2000000 .

 


Output

For each test case, print the answer modulo 109+7 in a single line.

 


Sample Input

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

 


Sample Output

 
 
240 54 144

 


Source

BestCoder Round #58 (div.2)

 


Recommend

hujie   |   We have carefully selected several similar problems for you:  5498 5497 5490 5489 5488 

 

考虑每个数字的贡献 ,显然是a[i]*2^(n-i)。

我们用sum记录前面的集合个数。

用mp[a[i]]]表示连续相同的数字对集合所产生的影响,即用sum-掉map[a[i]]]最终的子集的贡献。

#include<bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include  <cmath>
#include <map>
using namespace std;
#define inf 0x7f7f7f
typedef long long ll;
const ll N=1e5+100;
const ll mod=1e9+7;
ll a[N];
ll f[N];
map<ll,ll>mp;
int main()
{
    int i;
    int t;
    f[0]=1;
    for(i=1; i<N; i++)
        f[i]=f[i-1]*2%mod;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        for(i=1; i<=n; i++)
            scanf("%lld",&a[i]);
        ll ans=0;
        ll sum=1;
        mp.clear();
        for(i=1; i<=n; i++)
        {
            ans=(ans+a[i]*(sum-mp[a[i]])%mod*f[n-i]%mod)%mod;
            sum=(sum+f[i-1])%mod;
            mp[a[i]]=(mp[a[i]]+f[i-1])%mod;
        }
        ans+=mod;
        printf("%lld\n",ans%mod);
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值