10.1综合强化刷题 Day6
T1 排序
题目描述
小Z 有一个数字序列a1; a2; .... ; an,长度为n,小Z 只有一个操作:选
定p(1<p<n),然后把ap 从序列中拿出,然后再插⼊到序列中任意位置。
比如a 序列为1,2,4,5,3,p = 5,可以取出3,然后在任意位置插入,可
以变为1,2,3,4,5。
现在给你一个序列a,问你是否可以通过一次操作把整个序列从小到大
排好序(变成不降的)。
输入输出格式
输入格式:
第一行一个整数n,第二行空格隔开的n 个整数,代表a 序列。
输出格式:
如果可以n次操作可以排好序,输出”YES”,否则输出”NO”。
输入输出样例
5 1 2 4 5 3
YES
说明
对于30% 的数据,满足n <=1000。
对于60% 的数据,满足n <=10^5。
对于100% 的数据,满足n <=10^6; 1 <=ai <=10^6。
一个大模拟、、挺水的(具体模拟过程看代码吧)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 1000010
using namespace std;
int n,s,a[N],b[N];
int read()
{
,f=; char ch=getchar();
; ch=getchar();}
+ch-',ch=getchar();
return x*f;
}
int main()
{
// freopen("sort.in","r",stdin);
// freopen("sort.out","w",stdout);
n=read();
;i<=n;i++)
a[i]=read(),b[i]=a[i];
;i<=n;i++)
{
]) continue;
s++;
]>b[i]&&b[i-]>b[i+]) {printf(;}
]>b[i+]) b[i]=b[i-];
];
) {printf(;}
}
printf("YES");
;
}
AC代码
T2 同余方程组
题目描述
求关于x 的同余方程组
x%a1 = b1
x%a2 = b2
x%a3 = b3
x%a4 = b4
的大于等于0 的最小整数解。
输入输出格式
输入格式:
一行8 个整数,表示a1; b1; a2; b2; a3; b3; a4; b4。
输出格式:
一行一个整数,答案除以p 的余数。
输入输出样例
2 0 3 1 5 0 7 3
10
说明
对于30% 的数据,ai <=40, 保证ai 均为素数。
对于60% 的数据,1 <=ai <=10^3, 保证ai 均互素。
对于100% 的数据,0 <= bi < ai; 1 <=ai <= 10^3。
中国剩余定理裸题
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define N 5
#define ll long long
using namespace std;
ll n,m[N],a[N],m1,e;
ll read()
{
ll x=,f=; char ch=getchar();
; ch=getchar();}
+ch-'; ch=getchar();}
return x*f;
}
ll exgcd(ll a,ll b,ll &x,ll &y)
{
)
{
x=,y=;
return a;
}
ll r=exgcd(b,a%b,x,y),tmp;
tmp=x,x=y,y=tmp-a/b*y;
return r;
}
ll crt()
{
ll a1=a[],a2,m2,d,c;m1=m[];
;i<=n;++i)
{
a2=a[i],m2=m[i];
c=a2-a1;ll x=,y=;
d=exgcd(m1,m2,x,y);
;
x=x*c/d;
int mod=m2/d;
x=(mod+x%mod)%mod;
a1+=m1*x;m1*=mod;
}
return a1;
}
int main()
{
// freopen("mod.in","r",stdin);
// freopen("mod.out","w",stdout);
n=;
;i<=n;i++)
m[i]=read(),a[i]=read();
printf("%lld\n",crt());
;
}
Ac代码
T3 字符串
题目描述
如果把一个字符串从头到尾翻转后和原字符串相等,我们称之为回文串,比如“aabaa”、“())(”、“2017102”。
如果一个字符串存在两个出现过的字母出现的次数相等,我们称之为好
的字符串。
现在给一个由小写字母组成的字符串,问在这个字符串的所有连续的串
中,好的回文串有多少个。(两个相同的回文串出现在不同位置算多次)。
输入输出格式
输入格式:
一行一个小写字母组成的字符串。
输出格式:
一行一个整数,表示答案。
输入输出样例
abcbaabcba
6 【样例解释】 abcba s[1..5] a,b 出现次数相等 baab s[4..7] a,b 出现次数相等 cbaabc s[3..8] a,b 出现次数相等 bcbaabcb s[2..9] a,c 出现次数相等 abcbaabcba s[1..10] a,b 出现次数相等 abcba s[6..10] a,b 出现次数相等
说明
len 表示字符串长度。
对于30% 的数据, len <=10^2。
对于60% 的数据, len <= 10^3。
对于100% 的数据,1 <= len <= 10^4。
考试的时候,有位大智障竟然用(s[k]==s[j])!=0来判断,s[k]==s[j]&&s[k]!=0&&s[j]!=0 (捂脸、、)竟然在while里面先让b++,e--在统计这两个地方的每个字符的个数、、、(智障啊、、)
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 10010
using namespace std;
bool flag;
char ch[N];
int n,b,e,ans,s[N];
int main()
{
cin>>ch;n=strlen(ch);
;l<n;l++)
;i<n-l;i++)
{
b=i,e=l+i;flag=false;
memset(s,,sizeof(s));
while(b<=e)
{
if(ch[e]!=ch[b]) {flag=true;break;}
if(b==e) s[ch[e]-'a']++;
;
b++,e--;
}
;j<;j++)
{
if(flag) break;
;k<;k++)
if(s[j]&&s[k]&&s[j]==s[k]&&j!=k) {ans++,flag=true;break;}
}
}
printf("%d",ans);
;
}
30分暴力
气死我了、、玄学错误,一个枚举长度跟左端点,一个枚举左右端点,时间复杂度完全一样,结果一个TLE30分,另一个TLE60分!!!!!!!!
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 10010
using namespace std;
char ch[N];
int n,b,e,ans,s[N],tmp[N];
bool pd(int b,int e)
{
memset(s,,sizeof(s));
while(b<=e)
{
if(ch[e]!=ch[b]) return false;
if(b==e) s[ch[e]-'a']++;
;
b++,e--;
}
sort(s,s+);
;i>=;--i)
]) return true;
return false;
}
int main()
{
cin>>ch;n=strlen(ch);
;l<n;++l)
;i<n-l;++i)
{
b=i,e=l+i;
if(pd(b,e)) ans++;
}
printf("%d",ans);
;
}
枚举长度跟左端点 30分
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 10010
using namespace std;
char ch[N];
];
bool pd(int b,int e)
{
memset(s,,sizeof(s));
while(b<=e)
{
if(ch[e]!=ch[b]) return false;
if(b==e) s[ch[e]-'a']++;
;
b++,e--;
}
sort(s,s+);
;i>=;--i)
]) return true;
return false;
}
int main()
{
cin>>ch;n=strlen(ch);
;b<n-;++b)
;e<n;++e)
if(pd(b,e)) ans++;
printf("%d",ans);
;
}
枚举左右端点 60分
什么?! s数组开大了?! 开小点就是60?!!!
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 10010
using namespace std;
char ch[N];
];
bool pd(int b,int e)
{
memset(s,,sizeof(s));
while(b<=e)
{
if(ch[e]!=ch[b]) return false;
if(b==e) s[ch[e]-'a']++;
;
b++,e--;
}
sort(s,s+);
;i>=;--i)
]) return true;
return false;
}
int main()
{
cin>>ch;n=strlen(ch);
;l<n;++l)
;i<n-l;++i)
{
b=i,e=l+i;
if(pd(b,e)) ans++;
}
printf("%d",ans);
;
}
枚举长度跟左端点 60分
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
typedef unsigned long long ULL;
typedef long long LL;
];
ULL h[],rh[],pw[];
int L;
ULL hs(int l,int r){
]*pw[r-l+];
}
ULL rhs(int l,int r){
]*pw[r-l+];
}
struct N{
];
bool ok(){
];
;i<;i++) b[i]=a[i];
sort(b,b+);
;i<;i++){
&& b[i] == b[i+]) return true;
}
return false;
}
void clear(){
memset(a,,sizeof a);
}
};
LL ans=;
map<ULL,LL> num;
map<ULL,N> A;
void solve_odd(){
;i<=L;i++){
,r = min(i,L-i+)+;
){
;
,i+mid-)== rhs(i-mid+,i+mid-)) l=mid;
else r=mid;
}
int p=l;
int tmp = p;
&&num.find(hs(i-tmp+,i+tmp-))==num.end()) tmp--;
LL sum = ;
N st;
st.clear();
){
sum=num[hs(i-tmp+,i+tmp-)];
st = A[hs(i-tmp+,i+tmp-)];
}
while(tmp<p){
st.a[s[i+tmp]-?:);
if(st.ok()) sum++;
num[hs(i-tmp,i+tmp)] = sum;
A[hs(i-tmp,i+tmp)] = st;
tmp++;
}
ans+=sum;
// printf("# %d %lld\n",i,sum);
}
}
void solve_even(){
A.clear();
num.clear();
;i<L;i++){
// printf("### %d\n",i);
,r = min(i,L-i)+;
){
;
,i+mid)== rhs(i-mid+,i+mid)) l=mid;
else r=mid;
}
int p=l;
int tmp = p;
&&num.find(hs(i-tmp+,i+tmp))==num.end()) tmp--;
LL sum = ;
N st;
st.clear();
// printf("## %d\n",p);
){
sum=num[hs(i-tmp+,i+tmp)];
st = A[hs(i-tmp+,i+tmp)];
}
while(tmp<p){
// printf("# %d %lld\n",tmp,sum);
st.a[s[i+tmp+]-;
if(st.ok()) sum++;
num[hs(i-tmp,i+tmp+)] = sum;
A[hs(i-tmp,i+tmp+)] = st;
tmp++;
}
ans+=sum;
// printf("# %d %lld\n",i,sum);
}
}
int main(){
freopen("str.in","r",stdin);
freopen("str.out","w",stdout);
scanf();
L=strlen(s+);
s[]='#';
pw[]=;
;i<=L;i++) pw[i] = pw[i-]* ;
;i<=L;i++) h[i] = h[i-]* + s[i];
;i--) rh[i] = rh[i+]* + s[i];
// printf("%llu %llu",hs(1,3),rhs(1,3));
solve_odd();
solve_even();
printf("%lld\n",ans);
fclose(stdout);
;
}
标称(字符串+二分)
10.1综合强化刷题 Day6的更多相关文章
- 10.1综合强化刷题 Day3 morning
竞赛时间:????年??月??日??:??-??:?? 题目名称 a b c 名称 a b c 输入 a.in b.in c.in 输出 a.out b.out c.out 每个测试点时限 1s 1s ...
- 10.1综合强化刷题 Day3 afternoon
竞赛时间:????年??月??日??:??-??:?? 题目名称 a b c 名称 a b c 输入 a.in b.in c.in 输出 a.out b.out c.out 每个测试点时限 1s 1s ...
- 10.1综合强化刷题 Day2 morning
一道图论神题(god) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK有一张无向图G={V,E},这张无向图有n个点m条边组成.并且这是一张带权图,只有 ...
- 10.1综合强化刷题 Day2 afternoon
最大值(max) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK有一本书,上面有很多有趣的OI问题.今天LYK看到了这么一道题目: 这里有一个长度为n的 ...
- 10.1综合强化刷题 Day7
noip提高组模拟赛 ...
- 10.1综合强化刷题 Day1 afternoon
一道图论好题(graph) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK有一张无向图G={V,E},这张无向图有n个点m条边组成.并且这是一张带权图, ...
- 10.1综合强化刷题 Day5
T1 拼不出的数 lost.in/.out/.cpp[问题描述]3 个元素的集合{5; 1; 2}的所有子集的和分别是0; 1; 2; 3; 5; 6; 7; 8.发现最小的不能由该集合子集拼出的数字 ...
- 10.1综合强化刷题 Day4
财富(treasure) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK有n个小伙伴.每个小伙伴有一个身高hi. 这个游戏是这样的,LYK生活的环境是以 ...
- 10.1综合强化刷题 Day3
括号序列(bracket) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK有一个括号序列,但这个序列不一定合法. 一个合法的括号序列如下: ()是合法的 ...
随机推荐
- 利用本地SQL Server维护计划来维护SQL Database
On-Premise的SQL Server提供了维护计划来定期.定时的维护SQL Server.一般的做法是:定义SQL Server Agent Jobs,而后维护计划帮助我们定期.定时执行SQL ...
- billard:桌球的走位路线图解
这些是桌球的一些基础知识,记得刚学会桌球那会儿很强烈的想找到类似图片或资料,好久都找不到,最严重的时候只要一闭上眼睛,满脑子就是桌球的路线,线路图几乎是无处不在,痛苦的是经常能理解过来的很多路线因为杆 ...
- Kali 网络配置
一.配置IP 编辑/etc/network/interfaces # This file describes the network interfaces available on your syst ...
- 配置网络策略中的 NAP 条件
TechNet 库 Windows Server Windows Server 2008 R2 und Windows Server 2008 按类别提供的 Windows Server 内容 Win ...
- java web知识点
java web知识点 1.Java知识点 基本数据类型,面向对象,异常,IO,NIO,集合,多线程,JVM,高级特性. 2.web知识点 JSP,Serlvet,JDBC,Http 掌握Cookie ...
- leetcode 【 Search for a Range 】python 实现
题目: Given a sorted array of integers, find the starting and ending position of a given target value. ...
- python - 接口自动化测试 - basic_data - 基础数据参数化方法封装
# -*- coding:utf-8 -*- ''' @project: ApiAutoTest @author: Jimmy @file: basic_data.py @ide: PyCharm C ...
- Spider_Man_6 の Scrapy(未完待续)
一:自我介绍 Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架. 可以应用在包括数据挖掘,信息处理或存储历史数据等一系列的程序中.其最初是为了页面抓取 (更确切来说, 网络抓取 )所 ...
- 用python批量下载贴吧图片 附源代码
环境:windows 7 64位:python2.7:IDE pycharm2016.1 功能: 批量下载百度贴吧某吧某页的所有帖子中的所有图片 使用方法: 1.安装python2.7,安装re模块, ...
- spring IOC注解方式详解
本文分为三个部分:概述.使用注解进行属性注入.使用注解进行Bean的自动定义. 一,概述 注释配置相对于 XML 配置具有很多的优势: 它可以充分利用 Java 的反射机制获取类结构信息,这些信息可以 ...