2017 icpc 沈阳网络赛
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
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.
), for each test case:
there is one line contains two integers M
and K
.
.
20 15
90
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<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
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?
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
4 1
1 4 3 7
5 2
4 1 3 1 2
6 1
1 4 3 5 4 6
A is a magic array.
A is not a magic array.
#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
:
⋅
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.
Each test case includes an integer k
which is described above. (1≤k≤109
)
number mod 998244353.
#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
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.
(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)
.
4
10 40 15 30
1 2 30
1 3 2
3 4 10
#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
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.
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
.
4 6 2 8 4
1 5 7 9 2
[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]
#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
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.
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.
2
abcabc
3
abcabcabcabc
9
这题是不同长度串和长度为k的串的总数的综合体。k=1统计的是该字符串不同的子串的个数,k>1统计的是该字符串出现恰好k次的子串个数。k=1论文题,无需赘言。
#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 沈阳网络赛的更多相关文章
- 2018 ICPC 沈阳网络赛
2018 ICPC 沈阳网络赛 Call of Accepted 题目描述:求一个算式的最大值与最小值. solution 按普通算式计算方法做,只不过要同时记住最大值和最小值而已. Convex H ...
- 2017 icpc 南宁网络赛
2000年台湾大专题...英语阅读输入输出专场..我只能说很强势.. M. Frequent Subsets Problem The frequent subset problem is define ...
- 2017 icpc 西安网络赛
F. Trig Function 样例输入 2 0 2 1 2 2 样例输出 998244352 0 2 找啊找啊找数列和论文.cosnx可以用切比雪夫多项式弄成(cosx)的多项式,然后去找到了相关 ...
- 2018 ICPC 沈阳网络赛预赛 Supreme Number(找规律)
[传送门]https://nanti.jisuanke.com/t/31452 [题目大意]:给定一个数字(最大可达10100),现在要求不超过它的最大超级质数.超级质数定义:对于一个数,把它看成数字 ...
- 2019 ICPC 沈阳网络赛 J. Ghh Matin
Problem Similar to the strange ability of Martin (the hero of Martin Martin), Ghh will random occurr ...
- 2018 ICPC 徐州网络赛
2018 ICPC 徐州网络赛 A. Hard to prepare 题目描述:\(n\)个数围成一个环,每个数是\(0\)~\(2^k-1\),相邻两个数的同或值不为零,问方案数. solution ...
- hdu6212[区间dp] 2017青岛ACM-ICPC网络赛
原题: BZOJ1032 (原题数据有问题) /*hdu6212[区间dp] 2017青岛ACM-ICPC网络赛*/ #include <bits/stdc++.h> using name ...
- 2019 ICPC 南昌网络赛
2019 ICPC 南昌网络赛 比赛时间:2019.9.8 比赛链接:The 2019 Asia Nanchang First Round Online Programming Contest 总结 ...
- 沈阳网络赛 F - 上下界网络流
"Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a ...
随机推荐
- 【BZOJ】1270 [BeijingWc2008]雷涛的小猫
[算法]DP [题解]f1[i]表示第i棵树当前高度能得到的最多果子数 f2[i]表示高度i能得到的最多果子数. 于是有: f1[j]=max(f1[j],f2[i+delta])+mp[j][i]; ...
- python学习笔记(二)之python简单实践
1 安装python开发环境 Linux环境下自动安装好了python,可以通过以下命令更新到python最新版本. #echo "alias python=/usr/bin/python3 ...
- 随机生成数组函数+nth-element函数
这几天做了几道随机生成数组的题,且需要用nth-elemeng函数,并且都是北航出的多校题…… 首先我们先贴一下随机生成数组函数的代码: unsigned x = A, y = B, z = C; u ...
- 2017-2018-1 20179205《Linux内核原理与设计》第六周作业
<Linux内核原理与设计> 视频学习及操作 给MenuOS增加time和time-asm命令的方法: 1.更新menu代码到最新版 rm menu -rf //强制删除menu, rm ...
- 海量数据排序——如果有1TB的数据需要排序,但只有32GB的内存如何排序处理?
转载:https://blog.csdn.net/fx677588/article/details/72471357 1.外排序 传统的排序算法一般指内排序算法,针对的是数据可以一次全部载入内存中的 ...
- Linux进程调度与源码分析(三)——do_fork()的实现原理
用户层的fork(),vfork(),clone()API函数在执行时,会触发系统调用完成从用户态陷入到内核态的过程,而上述函数的系统调用,最终实现都是通过内核函数do_fork()完成,本篇着重分析 ...
- V4L2(二)虚拟摄像头驱动vivi深入分析【转】
转自:http://www.cnblogs.com/tureno/articles/6694463.html 转载于: http://blog.csdn.net/lizuobin2/article/d ...
- device tree 負值 property 寫法
倘若你要設定 負值的property, 可能需要括符才會 build 過. 正確 decidegc = <(-10)>; 錯誤 decidegc = <-10>;
- 1002: 当不成勇者的Water只好去下棋了---课程作业---图的填色
1002: 当不成勇者的Water只好去下棋了 Time Limit: 1 Sec Memory Limit: 128 MB Description 由于魔王BOSS躲起来了,说好要当勇者的Wate ...
- iOS APP程序启动原理
UIApplication 程序启动原理 一个应用程序运行就必须要有一个进程,一个进程至少要有一个线程,我们把这个线程叫做主线程,主线程开启之后会开启一个主运行循环,如果不开启一个运行循环,程序开启了 ...