2017 多校系列 6
来源:互联网 发布:linux 看cpu使用情况 编辑:程序博客网 时间:2024/06/05 22:40
Kirinriki
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 3009 Accepted Submission(s): 441
Problem Description
We define the distance of two strings A and B with same length n is
disA,B=∑i=0n−1|Ai−Bn−1−i|
The difference between the two characters is defined as the difference in ASCII.
You should find the maximum length of two non-overlapping substrings in given string S, and the distance between them are less then or equal to m.
The difference between the two characters is defined as the difference in ASCII.
You should find the maximum length of two non-overlapping substrings in given string S, and the distance between them are less then or equal to m.
Input
The first line of the input gives the number of test cases T; T test cases follow.
Each case begins with one line with one integers m : the limit distance of substring.
Then a string S follow.
Limits
T≤100
0≤m≤5000
Each character in the string is lowercase letter,2≤|S|≤5000
∑|S|≤20000
Each case begins with one line with one integers m : the limit distance of substring.
Then a string S follow.
Limits
Each character in the string is lowercase letter,
Output
For each test case output one interge denotes the answer : the maximum length of the substring.
Sample Input
15abcdefedcb
Sample Output
5Hint[0, 4] abcde[5, 9] fedcbThe distance between them is abs('a' - 'b') + abs('b' - 'c') + abs('c' - 'd') + abs('d' - 'e') + abs('e' - 'f') = 5
题解:运用尺取法,对字符串进行缩进。并且记录最大值。
ac code:
#include <sstream>#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <cstdlib>#include <cmath>#include <vector>#include <list>#include <deque>#include <queue>#include <iterator>#include <stack>#include <map>#include <set>#include <algorithm>#include <cctype>using namespace std;#define si1(a) scanf("%d",&a)#define si2(a,b) scanf("%d%d",&a,&b)#define sd1(a) scanf("%lf",&a)#define sd2(a,b) scanf("%lf%lf",&a,&b)#define ss1(s) scanf("%s",s)#define pi1(a) printf("%d\n",a)#define pi2(a,b) printf("%d %d\n",a,b)#define mset(a,b) memset(a,b,sizeof(a))#define forb(i,a,b) for(int i=a;i<b;i++)#define ford(i,a,b) for(int i=a;i<=b;i++)typedef long long LL;const int N=2e5+5;const int M=6666666;const int INF=0x3f3f3f3f;const double PI=acos(-1.0);const double eps=1e-7;const int mod=998244353;int m;string s;int solve(){ int len=s.length(); int ans=0; for(int i=len;i>=1;i--) { int cnt=i/2-1,t=0,p=0,d=0; for(int j=0;j<=cnt;j++) { d+=abs(s[j]-s[i-j-1]); if(d>m) { d-=abs(s[j]-s[i-j-1]); d-=abs(s[p]-s[i-p-1]); t--; j--; p++; } else { t++; ans=max(ans,t); } } } return ans;}int main(){ int T; si1(T); while(T--) { si1(m); cin>>s; int ans=0; ans=max(ans,solve()); reverse(s.begin(),s.end());//需要翻转一次确保答案最大 ans=max(ans,solve()); printf("%d\n",ans); }}
Inversion
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1826 Accepted Submission(s): 868
Problem Description
Give an array A, the index starts from 1.
Now we want to knowBi=maxi∤jAj , i≥2 .
Now we want to know
Input
The first line of the input gives the number of test cases T; T test cases follow.
Each case begins with one line with one integer n : the size of array A.
Next one line contains n integers, separated by space, ith number isAi .
Limits
T≤20
2≤n≤100000
1≤Ai≤1000000000
∑n≤700000
Each case begins with one line with one integer n : the size of array A.
Next one line contains n integers, separated by space, ith number is
Limits
Output
For each test case output one line contains n-1 integers, separated by space, ith number is Bi+1 .
Sample Input
241 2 3 441 4 2 3
Sample Output
3 4 32 4 4
ac code:
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <cstdlib>#include <cmath>#include <vector>#include <list>#include <deque>#include <queue>#include <iterator>#include <stack>#include <map>#include <set>#include <algorithm>#include <cctype>using namespace std;#define si1(a) scanf("%d",&a)#define si2(a,b) scanf("%d%d",&a,&b)#define sd1(a) scanf("%lf",&a)#define sd2(a,b) scanf("%lf%lf",&a,&b)#define ss1(s) scanf("%s",s)#define pi1(a) printf("%d\n",a)#define pi2(a,b) printf("%d %d\n",a,b)#define mset(a,b) memset(a,b,sizeof(a))#define forb(i,a,b) for(int i=a;i<b;i++)#define ford(i,a,b) for(int i=a;i<=b;i++)typedef long long LL;const int N=1100001;const int M=6666666;const int INF=0x3f3f3f3f;const double PI=acos(-1.0);const double eps=1e-7;const int mod=1e9+7;struct node{ int index,num;}a[700007];int b[700007];bool cmp(node x,node y){ return x.num>y.num;}int main(){ int T; si1(T); while(T--) { int n; si1(n); for(int i=1;i<=n;i++) { si1(a[i].num); a[i].index=i; } sort(a+1,a+1+n,cmp); //printf("%d\n",a[1]); int k=1,cnt=0; for(int i=2;i<=n;i++) { k=1; while(a[k].index%i==0) { k++; } b[cnt++]=a[k].num; } printf("%d",b[0]); for(int i=1;i<n-1;i++) { printf(" %d",b[i]); } printf("\n"); }}
Classes
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2048 Accepted Submission(s): 895
Problem Description
The school set up three elective courses, assuming that these courses are A, B, C. N classes of students enrolled in these courses.
Now the school wants to count the number of students who enrolled in at least one course in each class and records the maximum number of students.
Each class uploaded 7 data, the number of students enrolled in course A in the class, the number of students enrolled in course B, the number of students enrolled in course C, the number of students enrolled in course AB, the number of students enrolled in course BC, the number of students enrolled in course AC, the number of students enrolled in course ABC. The school can calculate the number of students in this class based on these 7 data.
However, due to statistical errors, some data are wrong and these data should be ignored.
Smart you must know how to write a program to find the maximum number of students.
Now the school wants to count the number of students who enrolled in at least one course in each class and records the maximum number of students.
Each class uploaded 7 data, the number of students enrolled in course A in the class, the number of students enrolled in course B, the number of students enrolled in course C, the number of students enrolled in course AB, the number of students enrolled in course BC, the number of students enrolled in course AC, the number of students enrolled in course ABC. The school can calculate the number of students in this class based on these 7 data.
However, due to statistical errors, some data are wrong and these data should be ignored.
Smart you must know how to write a program to find the maximum number of students.
Input
The first line of the input gives the number of test cases T; T test cases follow.
Each case begins with one line with one integer N, indicates the number of class.
Then N lines follow, each line contains 7 data: a, b, c, d, e, f, g, indicates the number of students enrolled in A, B, C, AB, BC, AC, ABC in this class.
It's guaranteed that at least one data is right in each test case.
Limits
T≤100
1≤N≤100
0≤a,b,c,d,e,f,g≤100
Each case begins with one line with one integer N, indicates the number of class.
Then N lines follow, each line contains 7 data: a, b, c, d, e, f, g, indicates the number of students enrolled in A, B, C, AB, BC, AC, ABC in this class.
It's guaranteed that at least one data is right in each test case.
Limits
Output
For each test case output one line contains one integer denotes the max number of students who enrolled in at least one course among N classes.
Sample Input
224 5 4 4 3 2 25 3 1 2 0 0 020 4 10 2 3 4 96 12 6 3 5 3 2
Sample Output
715HintIn the second test case, the data uploaded by Class 1 is wrong. Because we can't find a solution which satisfies the limitation. As for Class 2, we can calculate the number of students who only enrolled in course A is 2, the number of students who only enrolled in course B is 6, and nobody enrolled in course C,the number of students who only enrolled in courses A and B is 1, the number of students who only enrolled in courses B and C is 3, the number of students who only enrolled in courses A and C is 1, the number of students who enrolled in all courses is 2, so the total number in Class 2 is 2 + 6 + 0 + 1 + 3 + 1 + 2 = 15.
题解:有一些坑点注意下就好了,题目说有错误的数据。
ac code:
#include<stdio.h>#include<algorithm>#include<math.h>#include<stdlib.h>#include<string.h>#include<string>//#include<iostream>//#include<vector>//#include<queue>//#include<stack>//#include<map>//#include<set>#define scand(x) scanf("%d",&x)#define scandd(x,y) scanf("%d%d",&x,&y)#define mst(a,zero) memset(a,zero,sizeof(a))#define PARITY(value) (value&1)/*value>0*/#define IsPowerOfTwo(n) ((!(n&(n-1)) ) && n)#define INF 0x3f3f3f3f#define intinf 1e9#define llinf 1e18#define eps 1e-8#define PI acos(-1.0)using namespace std;typedef long long LL;const int N=1e6+10;const int M=1e6+10;const int maxn=1e6+10;const int mod=1e9+7;int n;int main(){ int T,a,b,c,d,e,f,g,sum,ans; scand(T); while(T--){ scand(n); ans=0; for (int i=0;i<n;i++){ sum=0; scanf("%d%d%d",&a,&b,&c); scanf("%d%d%d",&d,&e,&f); scanf("%d",&g); if(d>a) continue; if(d>b) continue; if(e>b) continue; if(e>c) continue; if(f>a) continue; if(f>c) continue; if(g>a) continue; if(g>b) continue; if(g>c) continue; if(g>d) continue; if(g>e) continue; if(g>f) continue; if(a-d-f+g<0) continue; if(b-d-e+g<0) continue; if(c-e-f+g<0) continue; sum=a+b+c-d-e-f+g; if (ans<sum)ans=sum; } printf("%d\n",ans); } return 0;}
阅读全文
0 0
- 2017 多校系列 6
- 2017 多校系列 1
- 2017 多校系列 2
- 2017 多校系列 3
- 2017 多校系列 4
- 2017 多校系列 5
- Learning python 系列6
- [SilkyBible] XviD系列-6
- 计算机基础知识扫盲系列6
- 算法系列6《MAC》
- 安卓面试题系列-6
- Leetcode--easy系列6
- greenDAO系列6--会话
- Craftyjs系列6-Assets
- AngularJS系列:6、指令
- 渣渣渣变渣渣系列(6)
- iOS面试系列6
- ○ 多客系列
- Mybatis返回HashMap时,某个字段值为null时,不会保存key
- cinder 基于镜像创建volume, 竟然下载镜像,问题排查
- torchvision安装
- 爬虫实践(四)--scrapy简单实践
- 51nod 1536不一样的猜数游戏 O(n)素数筛选法。同Codeforces 576A Vasya and Petya's Game。
- 2017 多校系列 6
- js选中checkbox
- Java中判断字符串是否为数字的五种方法
- 常用Android studio调用快捷键
- https://maven.google.com连接不上的解决办法
- shell脚本实现关闭指定程序名的进程
- D. The Union of k-Segments(扫描线)
- TSUNG学习教程 运行环境安装(一)
- http://zthdd.bokee.com/6189963.html