FR #3题解
A.
傻逼题?。。。前缀和什么的随便搞搞就好了。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 1000050
using namespace std;
int n,a[maxn],s[maxn],cnt[maxn][];
long long ans=;
char p[maxn];
int main()
{
scanf("%d",&n);
scanf("%s",p);
for (register int i=;i<=n;i++)
{
if (p[i-]=='a') a[i]=;else a[i]=-;
s[i]=s[i-]+a[i];
}
if (s[n]<) cnt[-s[n]][]++;else cnt[s[n]][]++;
for (register int i=n-;i>=;i--)
{
if (s[i]<) {ans+=(long long)cnt[-s[i]][];cnt[-s[i]][]++;}
else {ans+=(long long)cnt[s[i]][];cnt[s[i]][]++;}
}
printf("%lld\n",ans);
return ;
}
B.
我们可以用一个单调栈。分别维护左上右上左下右下的轮廓的情况。(类似于凸包,但有点不一样)。具体还是代码能说清楚,觉得这道题好神啊。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 100500
using namespace std;
struct pnt
{
int x,y;
pnt (int x,int y):x(x),y(y) {}
pnt () {}
}p[maxn],q[maxn<<];
int n,top=,m=,st[maxn];
int read()
{
char ch;int data=,f=;
while (ch<'' || ch>'')
{
if (ch=='-') f=-;
ch=getchar();
}
while (ch>='' && ch<='')
{
data=data*+ch-'';
ch=getchar();
}
return data*f;
}
bool cmp(pnt x,pnt y)
{
return x.x<y.x;
}
void work1()
{
top=;
for (int i=;i<=n;i++)
{
if ((!top) || ((p[i].x!=p[st[top]].x) && (p[st[top]].y<p[i].y))) st[++top]=i;
else if ((p[i].x==p[st[top]].x) && (p[i].y>p[st[top]].y)) st[top]=i;
}
q[++m]=p[st[top]];
for (int i=top-;i>=;i--)
{
q[++m]=pnt(p[st[i+]].x,p[st[i]].y);
q[++m]=p[st[i]];
}
return;
}
void work2()
{
top=;
for (int i=;i<=n;i++)
{
if ((!top) || ((p[i].x!=p[st[top]].x) && (p[i].y<p[st[top]].y))) st[++top]=i;
else if ((p[i].x==p[st[top]].x) && (p[i].y<p[st[top]].y)) st[top]=i;
}
q[++m]=p[st[]];
for (int i=;i<=top;i++)
{
q[++m]=pnt(p[st[i]].x,p[st[i-]].y);
q[++m]=p[st[i]];
}
return;
}
void work3()
{
top=;
for (int i=n;i>=;i--)
{
if ((!top) || ((p[i].x!=p[st[top]].x) && (p[i].y<p[st[top]].y))) st[++top]=i;
else if ((p[i].x==p[st[top]].x) && (p[i].y<p[st[top]].y)) st[top]=i;
}
q[++m]=p[st[top]];
for (int i=top-;i>=;i--)
{
q[++m]=pnt(p[st[i+]].x,p[st[i]].y);
q[++m]=p[st[i]];
}
return;
}
void work4()
{
top=;
for (int i=n;i>=;i--)
{
if ((!top) || ((p[i].x!=p[st[top]].x) && (p[i].y>p[st[top]].y))) st[++top]=i;
else if ((p[i].x==p[st[top]].x) && (p[i].y>p[st[top]].y)) st[top]=i;
}
q[++m]=p[st[]];
for (int i=;i<=top;i++)
{
q[++m]=pnt(p[st[i]].x,p[st[i-]].y);
q[++m]=p[st[i]];
}
return;
}
int main()
{
n=read();
for (int i=;i<=n;i++)
p[i].x=read(),p[i].y=read();
sort(p+,p+n+,cmp);
work1();
work2();
work3();
work4();
printf("%d\n",m);
for (int i=;i<=m;i++) printf("%d %d\n",q[i].x,q[i].y);
return ;
}
C.
朴素的爆搜是枚举每一位什么情况,然后dp判一下。
然后发现因为k很小但是位数很大,所以可以枚举0..k各有多少个。
然后加个高精就过啦。(我没加)
直接贴代码。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 505
using namespace std;
long long n,k,c[maxn][maxn],a[maxn],top=,ans=,bit[maxn];
bool vis[maxn][maxn];
void get_C()
{
c[][]=;
for (long long i=;i<=n;i++)
{
c[i][]=;
for (long long j=;j<=i;j++)
c[i][j]=c[i-][j-]+c[i-][j];
}
}
bool check()
{
long long sum=;for (long long i=;i<=k;i++) bit[i]=;
for (long long i=;i<=top;i++) {bit[a[i]]++;sum+=a[i];}
if (sum&) return false;
for (long long i=;i<=top;i++)
for (long long j=;j<=sum/;j++)
vis[i][j]=false;
vis[][]=true;
for (long long i=;i<=top;i++)
for (long long j=;j<=sum/;j++)
{
if (j>=a[i]) vis[i][j]=vis[i-][j]|vis[i-][j-a[i]];
else vis[i][j]=vis[i-][j];
if ((vis[i][j]) && (j==sum/)) return true;
}
return false;
}
void get_ans()
{
long long ret=n,ret2=;
for (long long i=;i<=k;i++)
{
ret2*=c[ret][bit[i]];
ret-=bit[i];
}
ans-=ret2;
}
void dfs(long long bit,long long n)
{
if (bit==k)
{
for (long long i=n;i>=;i--) a[++top]=k;
if (check()) get_ans();
for (long long i=n;i>=;i--) a[top--]=;
return;
}
dfs(bit+,n);long long ret=top;
for (long long i=;i<=n;i++)
{
a[++top]=bit;
dfs(bit+,n-i);
}
while (top!=ret) a[top--]=;
}
int main()
{
freopen("unlucky20.in","r",stdin);
freopen("unlucky20.out","w",stdout);
scanf("%lld%lld",&n,&k);
get_C();
for (long long i=;i<=n;i++) ans*=(k+);
dfs(,n);
printf("%lld\n",ans);
return ;
}
FR #3题解的更多相关文章
- FR #2题解
A. 考虑把(u,v)的询问离线挂在u上,然后dfs,每次从fath[x]到[x]相当于x子树dis区间加1,x子树以外区间-1,然后维护区间和区间平方和等. 常数略大. #include<io ...
- FR #1题解
A. 建图跑最小费用最大流.分类讨论每种情况如何连边,费用怎么定. #include<iostream> #include<cstdio> #include<cstrin ...
- SDOI2017 Round2 详细题解
这套题实在是太神仙了..做了我好久...好多题都是去搜题解才会的 TAT. 剩的那道题先咕着,如果省选没有退役就来填吧. 「SDOI2017」龙与地下城 题意 丢 \(Y\) 次骰子,骰子有 \(X\ ...
- THUSC2017 Day1题解
THUSC2017 Day1题解 巧克力 题目描述 "人生就像一盒巧克力,你永远不知道吃到的下一块是什么味道." 明明收到了一大块巧克力,里面有若干小块,排成n行m列.每一小块都有 ...
- Codeforces Round #545 Div1 题解
Codeforces Round #545 Div1 题解 来写题解啦QwQ 本来想上红的,结果没做出D.... A. Skyscrapers CF1137A 题意 给定一个\(n*m\)的网格,每个 ...
- HNOI2018简要题解
HNOI2018简要题解 D1T1 寻宝游戏 题意 某大学每年都会有一次 Mystery Hunt 的活动,玩家需要根据设置的线索解谜,找到宝藏的位置,前一年获胜的队伍可以获得这一年出题的机会. 作为 ...
- BJOI2018简要题解
BJOI2018简要题解 D1T1 二进制 题意 pupil 发现对于一个十进制数,无论怎么将其的数字重新排列,均不影响其是不是 \(3\) 的倍数.他想研究对于二进制,是否也有类似的性质. 于是他生 ...
- NOIP2014题解
NOIP2014题解 Day1 生活大爆炸版石头剪刀布 rps 简单模拟题,注意细节 #include<iostream> #include<cstdio> using nam ...
- NOIP2012题解
NOIP2012题解 Day1 Vigenère 密码 vigenere 直接模拟就好了,对于那张表找找规律就很短了. #include<iostream> #include<cst ...
随机推荐
- Qt之findChild
简述 在Qt编程过程中,通常会有多个部件嵌套,而大多数部件都有父子依赖关系,但是有些情况下不能直接引用子部件,这时我们可以通过父部件来findChild -"查找孩子". 简述 查 ...
- HDUOJ----2485 Destroying the bus stations(2008北京现场赛A题)
Destroying the bus stations ...
- Objective-C:Foundation框架-常用类-NSMutableString
NSString是不可变的,不能删除字符或修改字符,它有一个子类NSMutableString,为可变字符串. NSMutableString的两种创建方法: - (id) initWithCapac ...
- __attribute__特性介绍以及变量和函数特定布局设置
ARM的MDK编译__attribute__介绍:http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0348bc/Ciafc ...
- ODBC 小例
#include "stdafx.h"#include <windows.h>#include <stdio.h>#include <iostream ...
- 关于Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)的问题
找不到mysql socket的问题,我最近碰到了好多次重装系统以前,我的mysql,apache,php都是自己编译安装的,当时并没有碰到这些问题,重装系统以后,我的mysql是通过yum安装的,a ...
- OLAP vs OLTP: what makes the difference
OLAP vs OLTP: what makes the difference OLPT and OLAP are complementingtechnologies. You can't live ...
- Android 4.3正式发布:四大新功能一览
在旧金山举行的新品发布会上,Google正式发布了Android 4.3,代号仍为“Jelly Bean”.此次更新并没有太大改变,只是紧跟4.1.4.2步伐, 新增了低功耗蓝牙.多用户登录等一系列功 ...
- ACM心情总结
已经快要12点了,然而还有5000字概率论论文没有动.在论文里,我本来是想要总结一下ACM竞赛中出现过的概率论题目,然而当敲打第一段前言的时候,我就迟疑了. 我问自己,ACM竞赛到底有什么现实意义. ...
- Android Phonebook编写联系人UI加载及联系人保存流程(四)
2014-01-07 10:23:22 将百度空间里的东西移过来. 5. KindSectionView KindSectionView是何方神圣呢?它又是怎么怎么和一个DataKind,以及一个Ra ...