您的位置:首页 > 理论基础 > 计算机网络

2017 ACM/ICPC Asia Regional Shenyang Online

2017-09-17 10:10 309 查看
http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1002&cid=780

1002 cable cable cable

Problem Description

Connecting the display screen and signal sources which produce different color signals by cables, then the display screen can show the color of the signal source.Notice that every signal source can only send signals to one display screen each time.

Now you have M display screens and K different signal sources(K≤M≤232−1). Select K display screens from M display screens, how many cables are needed at least so that any K display screens you select can show exactly K different colors.

Input

Multiple cases (no more than 100), for each test case:

there is one line contains two integers M and K.

Output

Output the minimum number of cables N.

Sample Input

3 2

20 15

Sample Output

4

90

Hint

As the picture is shown, when you select M1 and M2, M1 show the color of K1, and M2 show the color of K2.

When you select M3 and M2, M2 show the color of K1 and M3 show the color of K2.

When you select M1 and M3, M1 show the color of K1.

分析: 我直接猜出来了公式。。。。k*(m-k+1)

看过程的点击http://blog.csdn.net/Enterprise_/article/details/77921977

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <string>
#include <set>
using namespace std;
#define mem(a,n) memset(a,n,sizeof(a))
typedef long long LL;
const int mod=1e9+7;
const double eps=1e-6;
const int INF=0x3f3f3f3f;
const int N=1e5+5;
int main()
{
LL m,k;
while(cin>>m>>k)
{
LL ans=k*(m-k+1);
cout<<ans<<endl;
}
return 0;
}


http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1004&cid=780

1004 array array array

Problem Description

One day, Kaitou Kiddo had stolen a priceless diamond ring. But detective Conan blocked Kiddo’s path to escape from the museum. But Kiddo didn’t want to give it back. So, Kiddo asked Conan a question. If Conan could give a right answer, Kiddo would return the ring to the museum.

Kiddo: “I have an array A and a number k, if you can choose exactly k elements from A and erase them, then the remaining array is in non-increasing order or non-decreasing order, we say A is a magic array. Now I want you to tell me whether A is a magic array. ” Conan: “emmmmm…” Now, Conan seems to be in trouble, can you help him?

Input

The first line contains an integer T indicating the total number of test cases. Each test case starts with two integers n and k in one line, then one line with n integers: A1,A2…An.

1≤T≤20

1≤n≤105

0≤k≤n

1≤Ai≤105

Output

For each test case, please output “A is a magic array.” if it is a magic array. Otherwise, output “A is not a magic array.” (without quotes).

Sample Input

3

4 1

1 4 3 7

5 2

4 1 3 1 2

6 1

1 4 3 5 4 6

Sample Output

A is a magic array.

A is a magic array.

A is not a magic array.

题意:给定长度为n(1<=n<=10^5)的序列,问从中删掉k(0<=k<=n)个元素后的序列是否满足非递增或者非递减。

思路:看题目的数据n,k的范围,太大了,肯定不能暴力删除k个来判断。

转换一下,如果已知某个子序列是非递增或非递减,那么判断子序列长度sz是否满足sz>=n-k

因为子序列有两种,所以只需要遍历两次就可以了

最长非递减子序列的问题

时间复杂度:O(nlogn)

*/

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <string>
#include <set>
using namespace std;
#define mem(a,n) memset(a,n,sizeof(a))
typedef long long LL;
const int mod=1e9+7;
const double eps=1e-6;
const int INF=0x3f3f3f3f;
const int N=1e5+5;
int a
,b
,s
;
///数组s为输入的序列
///按序列从前往后的顺序,数组a记录的是最长的非递增子序列的长度,数组b记录最长的非递减子序列
int main()
{
int T,n,k;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&k);
for(int i=0; i<=n; i++)
a[i]=b[i]=INF;
for(int i=0; i<n; i++)
{
scanf("%d",&s[i]);
*upper_bound(b,b+n,s[i])=s[i];
}
for(int i=n-1; i>=0; i--)
{
*upper_bound(a,a+n,s[i])=s[i];
}
int sz1=lower_bound(a,a+n,INF)-a;
int sz2=lower_bound(b,b+n,INF)-b;
if(sz1>=(n-k)||sz2>=(n-k))
puts("A is a magic array.");
else
puts("A is not a magic array.");
}
return 0;
}


1005 number number number

http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1005&cid=780

Problem Description

We define a sequence F:

⋅ F0=0,F1=1;

⋅ Fn=Fn−1+Fn−2 (n≥2).

Give you an integer k, if a positive number n can be expressed by

n=Fa1+Fa2+…+Fak where 0≤a1≤a2≤⋯≤ak, this positive number is mjf−good. Otherwise, this positive number is mjf−bad.

Now, give you an integer k, you task is to find the minimal positive mjf−bad number.

The answer may be too large. Please print the answer modulo 998244353.

Input

There are about 500 test cases, end up with EOF.

Each test case includes an integer k which is described above. (1≤k≤109)

Output

For each case, output the minimal mjf−bad number mod 998244353.

Sample Input

1

Sample Output

4

分析:可以推理出答案就是斐波那契数列的2*k+3项,但是题中的k最大为10^9,那么必须快速的求出斐波那契数列的第n项,就可以用到矩阵快速幂来求解,直接套用模板

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int mod=998244353;
typedef long long LL;
LL n;
typedef vector<LL>vec;
typedef vector<vec>mat;
mat mul(mat &A,mat &B)
{
mat C(A.size(),vec(B[0].size()));///分配大小,A的行,B的列
for(int i=0; i<A.size(); i++) ///矩阵A的行
for(int k=0; k<B.size(); k++) ///矩阵B的行
for(int j=0; j<B[0].size(); j++) ///矩阵B的列
C[i][j]=(C[i][j]+A[i][k]*B[k][j]%mod+mod)%mod;
return C;
}
///计算A^n
mat pow(mat A,LL n)
{
mat B(A.size(),vec(A.size()));///和矩阵A的大小相同
for(int i=0; i<A.size(); i++)
B[i][i]=1;
while(n>0)
{
if(n&1) B=mul(B,A);
A=mul(A,A);
n>>=1;
}
return B;
}

void solve()
{
mat A(2,vec(2));///2*2的矩阵
A[0][0]=1;
A[0][1]=1;
A[1][0]=1;
A[1][1]=0;
A=pow(A,n);
printf("%d\n",(A[1][0]%mod-1+mod)%mod);
}
int main()
{
while(~scanf("%lld",&n))
{
n=2*n+3;
solve();
}
}


1012 card card card

http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1012&cid=780

Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 2684 Accepted Submission(s): 755

Problem Description

As a fan of Doudizhu, WYJ likes collecting playing cards very much.

One day, MJF takes a stack of cards and talks to him: let’s play a game and if you win, you can get all these cards. MJF randomly assigns these cards into n heaps, arranges in a row, and sets a value on each heap, which is called “penalty value”.

Before the game starts, WYJ can move the foremost heap to the end any times.

After that, WYJ takes the heap of cards one by one, each time he needs to move all cards of the current heap to his hands and face them up, then he turns over some cards and the number of cards he turned is equal to the penaltyvalue.

If at one moment, the number of cards he holds which are face-up is less than the penaltyvalue, then the game ends. And WYJ can get all the cards in his hands (both face-up and face-down).

Your task is to help WYJ maximize the number of cards he can get in the end.So he needs to decide how many heaps that he should move to the end before the game starts. Can you help him find the answer?

MJF also guarantees that the sum of all “penalty value” is exactly equal to the number of all cards.

Input

There are about 10 test cases ending up with EOF.

For each test case:

the first line is an integer n (1≤n≤106), denoting n heaps of cards;

next line contains n integers, the ith integer ai (0≤ai≤1000) denoting there are ai cards in ith heap;

then the third line also contains n integers, the ith integer bi (1≤bi≤1000) denoting the “penalty value” of ith heap is bi.

Output

For each test case, print only an integer, denoting the number of piles WYJ needs to move before the game starts. If there are multiple solutions, print the smallest one.

Sample Input

5

4 6 2 8 4

1 5 7 9 2

Sample Output

4

Hint

For the sample input:

If WYJ doesn’t move the cards pile, when the game starts the state of cards is:

4 6 2 8 4

1 5 7 9 2

WYJ can take the first three piles of cards, and during the process, the number of face-up cards is 4-1+6-5+2-7. Then he can’t pay the the “penalty value” of the third pile, the game ends. WYJ will get 12 cards.

If WYJ move the first four piles of cards to the end, when the game starts the state of cards is:

4 4 6 2 8

2 1 5 7 9

WYJ can take all the five piles of cards, and during the process, the number of face-up cards is 4-2+4-1+6-5+2-7+8-9. Then he takes all cards, the game ends. WYJ will get 24 cards.

It can be improved that the answer is 4.

huge input, please use fastIO.

题意:求通过把最前面的一堆牌翻转到最后满足能把所有的牌的数目都取到的最少反转次数。

#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
const int N=1e6+5;
int a
,b
;
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=n;i++)
scanf("%d",&b[i]);
int sum=0,ans=0;
for(int i=1;i<=n;i++)
{
sum+=(a[i]-b[i]);
if(sum<0)
{
sum=0;
ans=i;
}
}
printf("%d\n",ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  网络赛
相关文章推荐