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 ...
随机推荐
- lua 闪电特效
闪电特效 根据不同的起点 终点 资源做倾斜 拉伸 ,主要是计算倾斜角度. function ZyLight:show(params) local params = params or {} local ...
- 超详细的Java面试题总结(三)之Java集合篇常见问题
List,Set,Map三者的区别及总结 List:对付顺序的好帮手 List接口存储一组不唯一(可以有多个元素引用相同的对象),有序的对象 Set:注重独一无二的性质 不允许重复的集合.不会有多个元 ...
- 【洛谷 P1452】 Beauty Contest (二维凸包,旋转卡壳)
题目链接 旋转卡壳模板题把. 有时间再补总结吧. #include <cstdio> #include <cmath> #include <algorithm> u ...
- 利用keepalive+mysql replication 实现数据库的高可用
利用keepalive+mysql replication 实现数据库的高可用 http://www.xuchanggang.cn/archives/866.html
- xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance(xsi:schemaLocation详解)
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"中xsi的意思是 :本xml文件中要用到某些来自xsi代表的“http:/ ...
- 计数排序的实现--适用于元素均较小的seq
今天无聊就打算把所有的排序算法都看一遍... 计数排序的时间复杂度是O(n),在算法导论中,用决策树模型中论证了,比较排序的情况为nlogn的复杂度.而计数排序的时间复杂度小于他的原因就是它不需要进行 ...
- Eclipse+Pydev+numpy+scipy+matplotlib
之前一直在linux环境下使用python,作为一枚小菜还是更喜欢windows.我使用python主要是进行科学计算,安装软件.搭建环境遇到了非常多的问题,特此总结. 一.python安装 版本:2 ...
- jequry_rotate.js用来写旋转类的东西的插件(如:抽奖转盘)
网上发现一个很有意思的jQuery旋转插件,支持Internet Explorer 6.0+ .Firefox 2.0 .Safari 3 .Opera 9 .Google Chrome,高级浏览器下 ...
- 【JBPM4】State 节点
State状态节点 相比 Task 节点的区别为: 主要是没有“操作人员”assignee 流程操作方便基本相同.如下: 部署流程: repositoryService.createDeploymen ...
- PL/SQL 11.6 注册码
PL/SQL Developer 下载地址:Download PL/SQL Developer 11.0.6 注册码 Product Code:4t46t6vydkvsxekkvf3fjnpzy5wb ...