cable cable cable

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

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.

 
Source
 
Recommend
liuyiding   |   We have carefully selected several similar problems for you:  6205 6204 6203 6202 6201 
 

 
在所有m个显示屏中选出k个,和光源有唯一连线。然后剩下(m-k)个显示屏都和k个光源都有连线,那么就保证无论怎么选都能有k种不同颜色。
于是方案数=k+(m-k)*k=k*(m-k+1)。
 #include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define LL long long
#define mod 998244353
using namespace std;
const int N=1e5+;
LL n,m,k;
int main()
{
while(scanf("%lld%lld",&n,&k)!=EOF)
{
printf("%lld\n",k*(n-k+));
}
return ;
}

array array array

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

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.
 
Source
 
Recommend
liuyiding   |   We have carefully selected several similar problems for you:  6205 6204 6203 6202 6201 

 
最长非递减子序列的模板题。数列从头到尾和从尾到头都来一遍。每次查询的是以a[i]结尾的序列的最长长度,更新的是a[i]这个位置点的最长长度。用树状数组更新和查询最大值就好了。
 #include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define LL long long
#define mod 998244353
using namespace std;
const int N=1e5+;
int n,m,k,t;
int a[N],bit[N],maxn;
int maxed(int i)
{
int s=;
while(i>)
{
s=max(bit[i],s);
i-=i&-i;
}
return s;
}
void add(int i,int x)
{
while(i<N)
{
bit[i]=max(bit[i],x);
i+=i&-i;
}
return ; }
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
}
clr(bit);
maxn=;
for(int i=;i<=n;i++)
{
t=maxed(a[i])+;
if(t>maxn)
maxn=t;
add(a[i],t);
}
clr(bit);
for(int i=n;i>=;i--)
{
t=maxed(a[i])+;
if(t>maxn)
maxn=t;
add(a[i],t);
}
if(n-k<=maxn)
printf("A is a magic array.\n");
else
printf("A is not a magic array.\n");
}
return ;
}

number number number

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

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
 
Source
 

fibonicci数列:1,1,2,3,5,8,13,21,34,55,89,144,233.....
打个表发觉对应各个k下的数为:4=1+3,12=4+8,33=12+21,88=33+55,232=88+144......
可以发现选k个数的fbonicci数列数集中没出现的最小整数f[i]=f[i-1]+fib[(i+1)*2];
于是写个3*3的矩阵快速幂同时加速fib与f[i]的运算就好了。
 #include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define LL long long
#define mod 998244353
using namespace std;
typedef vector<LL> vec;
typedef vector<vec> mat;
mat ori(,vec()),orip(,vec());
mat mart(,vec()),martp(,vec());
mat mul(const mat &a,const mat &b)
{
int row=a.size();
int col=b[].size();
int mid=b.size();
mat c(row,vec(col));
for(int i=;i<row;i++)
for(int j=;j<col;j++)
for(int k=;k<mid;k++)
c[i][j]=(c[i][j]+a[i][k]*b[k][j]%mod)%mod;
return c;
}
mat quick_pow(mat a,LL n)
{
int len=a.size();
mat res(len,vec(len));
for(int i=;i<len;i++)
res[i][i]=;
while(n)
{
if(n&)
res=mul(res,a);
a=mul(a,a);
n>>=;
}
return res;
}
void init()
{
orip[][]=;
orip[][]=;
orip[][]=;
martp[][]=;
martp[][]=;
martp[][]=;
martp[][]=;
martp[][]=;
martp[][]=;
return ;
}
int main()
{
LL n,m;
init();
while(scanf("%lld",&n)!=EOF)
{
ori=orip;
mart=martp;
mart=quick_pow(mart,n-);
ori=mul(ori,mart);
printf("%lld\n",ori[][]);
}
return ;
}

transaction transaction transaction

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others)
Total Submission(s): 877    Accepted Submission(s): 431

Problem Description
Kelukin is a businessman. Every day, he travels around cities to do some business. On August 17th, in memory of a great man, citizens will read a book named "the Man Who Changed China". Of course, Kelukin wouldn't miss this chance to make money, but he doesn't have this book. So he has to choose two city to buy and sell.
As we know, the price of this book was different in each city. It is ai

yuan

in i

t

city. Kelukin will take taxi, whose price is 1

yuan

per km and this fare cannot be ignored.
There are n−1

roads connecting n

cities. Kelukin can choose any city to start his travel. He want to know the maximum money he can get.

 
Input
The first line contains an integer T

(1≤T≤10

) , the number of test cases.
For each test case:
first line contains an integer n

(2≤n≤100000

) means the number of cities;
second line contains n

numbers, the i

th

number means the prices in i

th

city; (1≤Price≤10000)

then follows n−1

lines, each contains three numbers x

, y

and z

which means there exists a road between x

and y

, the distance is z

km

(1≤z≤1000)

.

 
Output
For each test case, output a single number in a line: the maximum money he can get.
 
Sample Input
1
4
10 40 15 30
1 2 30
1 3 2
3 4 10
 
Sample Output
8
 
Source
将此题分为两部分求解。一部分是以点u为lca的买书和过路的花费最小值leftmin。这部分可以用dfso(n)做出来,将子节点leftmin+路径花费和当前节点的花费(也就是当前节点买书)中较小者作为当前点leftmin,这个可以通过dfs回溯,在每个点o(子节点数目)解决,总的来说是访问每个点o(n)+子节点回溯o(n-1)的时间,也就是o(n)。然后求其他点到该点u的最小花费,显然该点花费-最小花费是该点可获得的最大利益。这个同样可以用一个dfs在o(n)的时间内解决。不排除常数的话差不多是3n的时间能解决该问题.
 #include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define LL long long
#define mod 998244353
using namespace std;
const int N=1e5+;
int T;
int n,m,u,v;
LL a[N],ck,maxn,ans,leftmin[N],allmin[N];
struct edg
{
int next,to;
LL val;
}edge[N*];
int head[N],ecnt,cnt;
void addedge(int u,int v,LL val)
{
edge[++ecnt]=(edg){head[u],v,val};
head[u]=ecnt;
return ;
}
void dfs(int u,int pre,LL val)
{
leftmin[u]=a[u];
for(int i=head[u];i!=-;i=edge[i].next)
{
if(edge[i].to!=pre)
{
dfs(edge[i].to,u,edge[i].val);
leftmin[u]=min(leftmin[edge[i].to]+edge[i].val,leftmin[u]);
}
}
return ;
}
void dfs2(int u,int pre,LL val)
{
allmin[u]=min(allmin[pre]+val,leftmin[u]);
maxn=max(maxn,a[u]-allmin[u]);
for(int i=head[u];i!=-;i=edge[i].next)
{
if(edge[i].to!=pre)
{
dfs2(edge[i].to,u,edge[i].val);
}
}
return ;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
clr_1(head);
ecnt=cnt=;
ans=maxn=;
for(int i=;i<=n;i++)
scanf("%lld",&a[i]);
for(int i=;i<n;i++)
{
scanf("%d%d%lld",&u,&v,&ck);
addedge(u,v,ck);
addedge(v,u,ck);
}
allmin[]=0x3f3f3f3f;
dfs(,,);
dfs2(,,);
printf("%lld\n",maxn);
}
return ;
}

card card card

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

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 i

th

integer ai

(0≤ai≤1000

) denoting there are ai

cards in i

th

heap;
then the third line also contains n

integers, the i

th

integer bi

(1≤bi≤1000

) denoting the "penalty value" of i

th

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

[pre]
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.**
[/pre]

 

题意比较难读懂的水题。。。我第一个开的就是这题,反正你们对着xx翻译看吧。。。看完就知道了。。。
要写个读入加速就对了。
 #include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define mod 1000000007
using namespace std;
const int N=1e6+;
typedef long long LL;
inline void getInt(LL* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '');
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * - ch + '';
}
}
else {
*p = ch - '';
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * + ch - '';
}
}
}
LL a[N],b[N],ans,maxn,lz,num;
int n,m,T,pos,prepos,rpos;
int main()
{
while(scanf("%d",&n)!=EOF)
{
for(int i=;i<=n;i++)
{
getInt(&a[i]);
}
for(int i=;i<=n;i++)
{
getInt(&b[i]);
}
maxn=;
ans=;
num=;
prepos=;
pos=;
rpos=;
for(int i=;i<=n;i++)
{
ans+=a[i]-b[i];
num+=a[i];
if(ans<)
{
prepos=pos;
pos=i;
if(num>maxn)
{
rpos=prepos;
maxn=num;
}
ans=;
num=;
}
}
for(int i=;i<=n;i++)
{
ans+=a[i]-b[i];
num+=a[i];
if(ans<)
{
prepos=pos;
pos=i;
if(num>maxn)
{
rpos=prepos;
maxn=num;
}
ans=;
num=;
if(prepos<=pos) break;
}
if(pos==i)
{
rpos=pos;
break;
}
}
printf("%d\n",rpos);
}
return ;
}

string string string

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

Problem Description
Uncle Mao is a wonderful ACMER. One day he met an easy problem, but Uncle Mao was so lazy that he left the problem to you. I hope you can give him a solution.
Given a string s, we define a substring that happens exactly k times as an important string, and you need to find out how many substrings which are important strings.
 
Input
The first line contains an integer T (T≤100) implying the number of test cases.
For each test case, there are two lines:
the first line contains an integer k (k≥1) which is described above;
the second line contain a string s (length(s)≤105).
It's guaranteed that ∑length(s)≤2∗106.
 
Output
For each test case, print the number of the important substrings in a line.
 
Sample Input
2
2
abcabc
3
abcabcabcabc
 
Sample Output
6
9
 

这题是不同长度串和长度为k的串的总数的综合体。k=1统计的是该字符串不同的子串的个数,k>1统计的是该字符串出现恰好k次的子串个数。k=1论文题,无需赘言。
k>1的话我们遍历一遍sa数组,每次选位置p开始的连续k个字符串,求出他们最长公共前缀,该前缀任何前缀大于等于k次的前缀。那么我们再算出该前缀中大于k次的前缀,减掉就好了。这大于k次的前缀的长度是p-1~p+k和p~p+k+1中最长公共前缀较大者,但不超过连续k串最长公共前缀的长度。这些都能由height解决。上述操作就是height中就是找连续k-1个里的最小值,然后找p-1和p+1中较大值,若(最小值-较大值)<=0说明这连续k串都大于k次,对答案没贡献。否则有(最小值-较大值)串是正好出现k次的。我用mutiset动态存储height,效果很不错。
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#define clr(x) memset(x,0,sizeof(x))
#define clrmax(x) memset)x,0x3f3f3f3f,sizeof(x))
using namespace std;
const int N=1e5+;
int ranked[N],order[N],backet[N],sa[N],key1[N],key2[N],height[N];
char s[N],vis[];
int n,m,ans,k;
int unrep[N];
multiset<int> sum;
multiset<int>::iterator it;
bool cmp(int *r,int a,int b,int len)
{
return r[a]==r[b] && r[a+len]==r[b+len];
}
void da(int *sa,char *r,int n,int m)
{
int i,j,p,*x=key1,*y=key2,*t;
for(i=;i<m;i++) backet[i]=;
for(i=;i<n;i++) backet[x[i]=r[i]]++;
for(i=;i<m;i++) backet[i]+=backet[i-];
for(i=n-;i>=;i--) sa[--backet[x[i]]]=i;
for(j=,p=;p<n;j*=,m=p)
{
for(p=,i=n-j;i<n;i++) y[p++]=i;
for(i=;i<n;i++) if(sa[i]>=j) y[p++]=sa[i]-j;
for(i=;i<n;i++) order[i]=x[y[i]];
for(i=;i<m;i++) backet[i]=;
for(i=;i<n;i++) backet[order[i]]++;
for(i=;i<m;i++) backet[i]+=backet[i-];
for(i=n-;i>=;i--) sa[--backet[order[i]]]=y[i];
for(t=x,x=y,y=t,p=,x[sa[]]=,i=;i<n;i++)
x[sa[i]]=cmp(y,sa[i-],sa[i],j)?p-:p++;
}
return ;
}
void calheight(int *sa,char *r,int n)
{
int i,j,k=;
for(i=;i<=n;i++) ranked[sa[i]]=i;
for(i=;i<n;i++)
{
if(k) k--;
j=sa[ranked[i]-];
while(r[i+k]==r[j+k]) k++;
height[ranked[i]]=k;
}
return ;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
ans=;
scanf("%d",&k);
scanf("%s",s);
n=strlen(s);
n++;
da(sa,s,n,);
n--;
calheight(sa,s,n);
if(k==)
{
height[]=height[n+]=;
for(int i=;i<=n;i++)
ans+=n-sa[i]-max(height[i],height[i+]);
printf("%d\n",ans);
continue;
}
sum.clear();
k--;
height[]=;
height[n+]=;
for(int i=;i<=k;i++)
sum.insert(height[i]);
for(int i=k+;i<=n;i++)
{
sum.insert(height[i]);
it=sum.begin();
ans+=max(*it-max(height[i-k],height[i+]),);
sum.erase(sum.find(height[i-k+]));
}
printf("%d\n",ans);
}
return ;
}

2017 icpc 沈阳网络赛的更多相关文章

  1. 2018 ICPC 沈阳网络赛

    2018 ICPC 沈阳网络赛 Call of Accepted 题目描述:求一个算式的最大值与最小值. solution 按普通算式计算方法做,只不过要同时记住最大值和最小值而已. Convex H ...

  2. 2017 icpc 南宁网络赛

    2000年台湾大专题...英语阅读输入输出专场..我只能说很强势.. M. Frequent Subsets Problem The frequent subset problem is define ...

  3. 2017 icpc 西安网络赛

    F. Trig Function 样例输入 2 0 2 1 2 2 样例输出 998244352 0 2 找啊找啊找数列和论文.cosnx可以用切比雪夫多项式弄成(cosx)的多项式,然后去找到了相关 ...

  4. 2018 ICPC 沈阳网络赛预赛 Supreme Number(找规律)

    [传送门]https://nanti.jisuanke.com/t/31452 [题目大意]:给定一个数字(最大可达10100),现在要求不超过它的最大超级质数.超级质数定义:对于一个数,把它看成数字 ...

  5. 2019 ICPC 沈阳网络赛 J. Ghh Matin

    Problem Similar to the strange ability of Martin (the hero of Martin Martin), Ghh will random occurr ...

  6. 2018 ICPC 徐州网络赛

    2018 ICPC 徐州网络赛 A. Hard to prepare 题目描述:\(n\)个数围成一个环,每个数是\(0\)~\(2^k-1\),相邻两个数的同或值不为零,问方案数. solution ...

  7. hdu6212[区间dp] 2017青岛ACM-ICPC网络赛

    原题: BZOJ1032 (原题数据有问题) /*hdu6212[区间dp] 2017青岛ACM-ICPC网络赛*/ #include <bits/stdc++.h> using name ...

  8. 2019 ICPC 南昌网络赛

    2019 ICPC 南昌网络赛 比赛时间:2019.9.8 比赛链接:The 2019 Asia Nanchang First Round Online Programming Contest 总结 ...

  9. 沈阳网络赛 F - 上下界网络流

    "Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a ...

随机推荐

  1. 【BZOJ】1270 [BeijingWc2008]雷涛的小猫

    [算法]DP [题解]f1[i]表示第i棵树当前高度能得到的最多果子数 f2[i]表示高度i能得到的最多果子数. 于是有: f1[j]=max(f1[j],f2[i+delta])+mp[j][i]; ...

  2. python学习笔记(二)之python简单实践

    1 安装python开发环境 Linux环境下自动安装好了python,可以通过以下命令更新到python最新版本. #echo "alias python=/usr/bin/python3 ...

  3. 随机生成数组函数+nth-element函数

    这几天做了几道随机生成数组的题,且需要用nth-elemeng函数,并且都是北航出的多校题…… 首先我们先贴一下随机生成数组函数的代码: unsigned x = A, y = B, z = C; u ...

  4. 2017-2018-1 20179205《Linux内核原理与设计》第六周作业

    <Linux内核原理与设计> 视频学习及操作 给MenuOS增加time和time-asm命令的方法: 1.更新menu代码到最新版 rm menu -rf //强制删除menu, rm ...

  5. 海量数据排序——如果有1TB的数据需要排序,但只有32GB的内存如何排序处理?

    转载:https://blog.csdn.net/fx677588/article/details/72471357 1.外排序  传统的排序算法一般指内排序算法,针对的是数据可以一次全部载入内存中的 ...

  6. Linux进程调度与源码分析(三)——do_fork()的实现原理

    用户层的fork(),vfork(),clone()API函数在执行时,会触发系统调用完成从用户态陷入到内核态的过程,而上述函数的系统调用,最终实现都是通过内核函数do_fork()完成,本篇着重分析 ...

  7. V4L2(二)虚拟摄像头驱动vivi深入分析【转】

    转自:http://www.cnblogs.com/tureno/articles/6694463.html 转载于: http://blog.csdn.net/lizuobin2/article/d ...

  8. device tree 負值 property 寫法

    倘若你要設定 負值的property, 可能需要括符才會 build 過. 正確 decidegc = <(-10)>; 錯誤 decidegc = <-10>;

  9. 1002: 当不成勇者的Water只好去下棋了---课程作业---图的填色

    1002: 当不成勇者的Water只好去下棋了 Time Limit: 1 Sec  Memory Limit: 128 MB Description 由于魔王BOSS躲起来了,说好要当勇者的Wate ...

  10. iOS APP程序启动原理

    UIApplication 程序启动原理 一个应用程序运行就必须要有一个进程,一个进程至少要有一个线程,我们把这个线程叫做主线程,主线程开启之后会开启一个主运行循环,如果不开启一个运行循环,程序开启了 ...