2017 ACM/ICPC Asia Regional Shenyang Online(9.10)

总结下这两天做的题目,昨天的题目与图相关的很多,图的题一般就是遇到没见过就gg了,比如那个有向的加强图那个,,沈阳这个有两个推公式的,但是只过了一个。。。number number number这个题明明结束前显示是过了的,服务器崩了我们三条机器都显示是过了的,刚才回去看的时候成了Output Limit Exceeded,剪不断理还乱风水乱流转苍天饶过谁啊,还有一个最长上升子序列的,写的dp一直超时,后来队友给我改了改a了,换了种方法选最长子序列。一直纠结于那么几个题,导致最后相对容易的拿个根本没人去看,没时间了,匆匆忙忙瞎了已一发,没反馈,就gg了,做题不能“恋战”,有的题真是坑死人。

1002

k盏灯  n个屏幕   从n个屏幕中选择k个  求保证这k盏灯颜色不相同的最少的导线 

签到题   队友给我讲了讲意思之后,一下就推出(试出)了公式,k+(n-k)k

这个推到的过程大致就是先把边缘的每一个屏幕连接一盏灯。边缘的先先去掉,这样先保证,对于剩下的n-k个屏幕肯定要至少k种颜色,加上试几个数据,公式就来了

1004

给出一个n的序列和一个k   从中拿出k个数来,剩下的数据中,问你是不是非递增或者非递减的数列

刚开始没什么思路,一直纠结于n个里面拿k个,选择太多了,暴力是绝对不行的,大约卡了半个小时,突然灵光一现,既然是要非递增或者非递减,拿就先把递增或者递减的最长序列的个数求出来,这样剩下的数据如果比k大说明就算k个全拿了递增或者递减序列里的数也无济于事,所以只要满足剩下的数据m<=k即可,<的情况就是剩下的拿出来的数据不够,可以从递增或者递减数列的首尾部位借几个,这样就基本可以做了,无奈的就是写了个最长上升和下降之后超时了

1005

题意很简单,从斐波那契数列里选出k个数据来,求其和,问不能组成的最小的数是多少

数据很大,这一看就不能暴力,一度想求出所有的各项,但是发现不现实,不论是递推求,还是公式求,都是不可行的,后来根据强行写出的项,推出最终的公式,ans=F(2*n+1)-1,完美,现在就只剩下解决斐波那契的事了,听到其他的队伍用什么矩阵求各项,到我那个上百度了个模板,提交之后,一度显示是过了,在排名巴黎斗仙是的过了,但是到莫名其妙的现在又成了没过了。

1012

给出一个序列第一行的,还有惩罚值第二行的,你可以移动一些前面的去队伍的后面求最大的子段和,条件是他必须得大于下面其对应的惩罚值的和,中间有其和加起来比下面的小了就得停止了,问你最少移动几下可以得到最大的值

前面根本没看这个题,最后的时候才知道原来相对于其他的来说还算容易的,匆匆茫茫写的那一个代码,答题思路就是按照题意模拟,因为是可以从尾再到头,所以直接在尾部在加上一段,这样直接循环下来,暴力全部走一遍,所以服务器崩了,一直没有回馈,也没再管,刚才到网上看了看有没有什么更好的方法,

最大子段和思想,对两序列的差,和第一行系列,同时进行。

果然,这种思想更好理解了,做法上和我的基本相似,求子段和更优了,找到小鱼0的时候就结束游戏,重开,在此同时,记录下位置即可,这个题只交了一次,运行错误,是因为数组开小了,如果服务器不崩溃,再改进几次说不一定也可以按照我的那种写过,只可惜看的太晚了这个题

1002

 

cable cable cable

 

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

 

 

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.

#include <iostream>
#include <cstring>
#include <stdio.h>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
    long long n,k;
    while (scanf("%lld%lld",&n,&k)!=EOF){
        printf("%lld\n",k+(n-k)*k);
    }
}

 

1004

array array array

 

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

 

 

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.

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<cstring>
#include<algorithm>
using namespace std;
int map[1000010];
int dp[1000010];
int dp1[1000010];
int main()
{
    int temp;
    int i,j;
    int t;
    scanf("%d",&t);
    int n,k;
    while(t--)
    {
        scanf("%d %d",&n,&k);
        memset(dp,0,sizeof(dp));
        memset(dp1,0,sizeof(dp1));
        int max1 = 0;
        int max2 = 0;
        int flag = 0;
        for(i=1;i<=n;i++){
            scanf("%d",&map[i]);
        }
        dp[1] = map[1];
        int length = 1;
        for (int i = 2; i <= n; i++){
            if (map[i] > dp[length])
            dp[++length] = map[i];
            else{
                int p = lower_bound(dp,dp + length,map[i]) - dp;
                dp[p] = map[i];
            }
        }
        dp1[1] = map[1];
        int length1 = 1;
        for (int i = n; i >= 2 ; i--){
            if (map[i] > dp[length1])
            dp[++length1] = map[i];
            else{
                int p = lower_bound(dp,dp + length1,map[i]) - dp;
                dp[p] = map[i];
            }
        }
        if (n - length <= k || n - length1 <= k)
            printf("A is a magic array.\n");
        else
            printf("A is not a magic array.\n");
    }
    return 0;
}

 

1005

 

 

number number number

 

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

 

 

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

#include <iostream>//这个代码是未通过的  但是思路就是这样的   根据公式  解决数据范围就基本没有问题了
#include <cstring>
#include <stdio.h>
#include <algorithm>
#include <cmath>
using namespace std;
using namespace std;
const int MOD = 10000;
struct matrix {
    int m[2][2];
}ans;
matrix base = {1, 1, 1, 0};
matrix multi(matrix a, matrix b) {
    matrix tmp;
    for(int i = 0; i < 2; i++) {
        for(int j = 0; j < 2; j++) {
            tmp.m[i][j] = 0;
            for(int k = 0;  k < 2; k++)
                tmp.m[i][j] = (tmp.m[i][j] + a.m[i][k] * b.m[k][j]) % MOD;
        }
    }
    return tmp;
}
int matrix_pow(matrix a, int n) {
    ans.m[0][0] = ans.m[1][1] = 1;
    ans.m[0][1] = ans.m[1][0] = 0;
    while(n) {
        if(n & 1) ans = multi(ans, a);
        a = multi(a, a);
        n >>= 1;
    }
    return ans.m[0][1];
}
int main() {
    int n;
    /*while(cin>>n)
    {
        cout<<n<<endl;
    }*/
    while(scanf("%d",&n))
    {
        n++;
        printf("%d\n",(matrix_pow(base,2*n+1)-1)%998244353);
    }
    return 0;
}

 

1012

 

card card card

 

 

 

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0

 

 

 

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<stdio.h>		//贴个代码吧
				//添上几句注释
typedef long long ll;
const int MAX=1e6+5;
const int INF=0x3f3f3f3f;
int n,a[3*MAX],b[3*MAX];
int main()
{
    while(~scanf("%d",&n))
    {
        int s=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            a[i+n]=a[i];		//  先构建循环的数列
        }
        for(int i=1;i<=n;i++)
        {
            int x;
            scanf("%d",&x);
            b[i]=a[i]-x;		//做差的最大子段和
            b[i+n]=b[i];
        }
        int sum=0,suma=0;
        int maxa=-INF;
        int l,r,temp=1;
        for(int i=1;i<=2*n;i++)  
        {  
            suma+=a[i];			//最终需要的最大值
            sum+=b[i];			//判断的差值  <0则结束		
            if(suma>maxa)
            {
                maxa=suma;
                l=temp;
                r=i;
            }
            if(sum<0)
            {
                suma=0;
                sum=0;
                temp=i+1;
                if(temp>n+1)break;
            }
        }  
        printf("%d\n",l-1);
    }
    return 0;
}

 

 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值