[Codeforces #494] Tutorial
记录下一开始写错的两道水题
E:
先建出直径,然后在保证直径不变的情况下按照最大度数贪心就好了
注意一下一开始的特判
#include <bits/stdc++.h> using namespace std;
#define X first
#define Y second
typedef pair<int,int> P;
int n,d,k,tot;vector<P> res; void print()
{
puts("YES");
for(int i=;i<res.size();i++)
printf("%d %d\n",res[i].X,res[i].Y);
} void dfs(int u,int v,int dist,int idx)
{
if(u) res.push_back(P(u,v));
if(tot==n) print(),exit();
if(!dist) return;
for(int i=;i<=idx;i++)
dfs(v,++tot,dist-,k-);
} int main()
{
scanf("%d%d%d",&n,&d,&k);
if(n<=d||n>&&k<) return puts("NO");
for(int i=;i<=d;i++) res.push_back(P(i,i+));
tot=d+;if(tot==n) return print(),;
for(int i=;i<=d;i++)
if(tot<n&&k>) dfs(,i,min(i-,d-i+),k-);
puts("NO");
return ;
}
Problem E
F:
又双叒叕看错题目了,可以缩减多个相同的串……
一开始写的$KMP$,后来发现直接字符串$Hash$就能水过了
注意:此题用$ab$串卡自然溢出,一共只有300个因此单模数就能过
数据开头$dont hash with overflow$好评!
#include <bits/stdc++.h> using namespace std;
typedef unsigned long long ull;
typedef pair<int,int> P; const int MAXN=;
ull hs[MAXN],MOD=;char s[];
int n,res,tot,len,pre[MAXN]; ull cal_hash()
{
ull ret=;
for(int i=;i<strlen(s);i++)
ret=(ret*+(s[i]-'a'+))%MOD;
return ret;
} int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%s",s);int len=strlen(s);
tot+=len;pre[i]=pre[i-]+len;hs[i]=cal_hash();
}
tot+=n-; for(int i=;i<=n;i++)
for(int j=i;j<=n;j++)
{
int cnt=;
for(int k=j+;k+j-i<=n;k++)
{
bool f=true;
for(int l=;l<=j-i;l++)
if(hs[i+l]!=hs[k+l]) f=false;
if(f) cnt++,k+=j-i;
}
if(cnt>) res=max(res,(pre[j]-pre[i-]-)*cnt);
}
printf("%d",tot-res);
return ;
}
Problem F
[Codeforces #494] Tutorial的更多相关文章
- [Codeforces #172] Tutorial
Link: Codeforces #172 传送门 A: 一眼看上去分两类就可以了 1.每个矩形只有两条边相交,重合的形状为菱形 2.每个矩形四条边都有相交 对于情况1答案为$h*h/sin(a)$ ...
- [Codeforces #514] Tutorial
Link: Codeforces #514 传送门 很简单的一场比赛打崩了也是菜得令人无话可说…… D: 一眼二分,发现对于固定的半径和点,能包含该点的圆的圆心一定在一个区间内,求出区间判断即可 此题 ...
- [Codeforces #210] Tutorial
Link: Codeforces #210 传送门 A: 贪心,对每个值都取最大值,不会有其他解使答案变优 #include <bits/stdc++.h> using namespace ...
- [Codeforces #196] Tutorial
Link: Codeforces #196 传送门 A: 枚举 #include <bits/stdc++.h> using namespace std; #define X first ...
- [Codeforces #174] Tutorial
Link: Codeforces #174 传送门 A: 求原根的个数,有一条性质是原根个数为$\phi(\phi(n))$,多了一个不会证的性质 如果要确定哪些是原根的话还是要枚举,不过对于每个数不 ...
- [Codeforces #190] Tutorial
Link: Codeforces #190 传送门 A: 明显答案为$n+m-1$且能构造出来 #include <bits/stdc++.h> using namespace std; ...
- [Codeforces #211] Tutorial
Link: Codeforces #211 传送门 一套非常简单的题目,但很多细节都是错了一次才能发现啊…… 还是不能养成OJ依赖症,交之前先多想想corner case!!! A: 模拟,要特判0啊 ...
- [Codeforces #192] Tutorial
Link: Codeforces #192 传送门 前两天由于食物中毒现在还要每天挂一天的水 只好晚上回来随便找套题做做找找感觉了o(╯□╰)o A: 看到直接大力模拟了 但有一个更简便的方法,复杂度 ...
- [Codeforces #201] Tutorial
Link: 传送门 代码量很少的一套思维题 A: 试一试发现最后状态一定是所有$min,max$间$gcd$的倍数 直接判断数量的奇偶性即可 #include <bits/stdc++.h> ...
随机推荐
- web_一些常用的线上脚本地址记录(个人使用)
1.jquery <script src="http://code.jquery.com/jquery-1.4.1.min.js"></script> 2. ...
- 更新ubuntu15.10后触摸板点击功能消失
问题描述: 昨天升级了ubuntu15.10,升级之后很多15.04让人不爽的东西消失了,大快人心,但是突然发现自己的触摸板不怎么好用了,原来可以点击,双指点击代表右键,三指点击代表鼠标中键的功能不见 ...
- C# 使用HttpWebRequest Post提交数据,携带Cookie和相关参数示例
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 一个朋友 js图表开发问题 用 c和 js 解决
引言 不求知道一切, 只求发现一件 -- 乔治·西蒙·欧姆 附注:那些存在于梦幻中的事迹,那些儿时梦中的人物,每每看起,都觉得 .哎 .... 岁月 ... 一直在努力 ... ...
- XML 约束 (DTD和 schema)
book.DTD 如下: <?xml version="1.0" encoding="UTF-8" ?> <schema xmlns=&quo ...
- windows系统安装mysql压缩zip版
1.下载 打开官网:https://www.mysql.com 进入DOWNLOADS--->Community--->MySQL Community Server,选择系统对应的版本点击 ...
- Leetcode 之Binary Tree Postorder Traversal(47)
中序遍历二叉搜索树,得到的是一个有序的结果,找出其中逆序的地方就可以了.如果逆序的地方相邻,只需把逆序的相换即可:如果不相邻,则需要找到第二个逆序对的 第二个元素再做交换. 定义两个指针p和q来指定需 ...
- HDU 3669 Cross the Wall(斜率DP+预处理)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3669 题目大意:有n(n<=50000)个矩形,每个矩形都有高和宽,你可以在墙上最多挖k个洞使得 ...
- python安装numpy和scipy的资源
whl资源:注意python版本和位数. http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
- html5 -audio-移动端如何自动播放
最近在做一些活动类页面或者类似于易企秀类型的轻应用经常遇到关于audio标签的应用,对于audio相关的常用知识点以及一些相关的问题如下: <audio id="audios" ...