[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> ...
随机推荐
- 【NOIP】提高组2012 国王游戏
[题意] 恰逢H国国庆,国王邀请n位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右 手上面分别写下一个整数,国王自己也在左.右手上各写一个整数.然后,让这n位大臣排 成一排,国王站在队伍的最前面.排 ...
- bzoj 3524 可持久化线段树
我们可以先离散化,然后建立权值的可持久化线段树,记录每个数出现的次数,对于区间询问直接判断左右儿子的cnt是不是大于(r-k+1)/2,然后递归到最后一层要是还是大于就有,否则不存在. 反思:挺简单一 ...
- hdu 1272 小希的迷宫(并查集+最小生成树+队列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1272 小希的迷宫 Time Limit: 2000/1000 MS (Java/Others) ...
- 实战手工注入某站,mssql注入
昨天就搞下来的,但是是工具搞得,为了比赛还是抛弃一阵子的工具吧.内容相对简单,可掠过. 报错得到sql语句: DataSet ds2 = BusinessLibrary.classHelper.Get ...
- smb windows中使用的文件共享协议(主要用于与windows互通)
主要是samba服务. SMB协议又成为CIFS(Common Internet File System)协议 samba服务功能: 1文件共享 2打印共享 3加入windows2000/2003/2 ...
- Redis 3.0 编译安装
Redis 3.0 编译安装 http://www.xuchanggang.cn/archives/991.html
- 【LOJbeta round1】ZQC的手办
NOI2012-超级钢琴的升级版. 用线段树维护最小值及其出现位置,接下来就跟超级钢琴一个做法了. #include<bits/stdc++.h> #define N 500010 #de ...
- 【NOIP2016】组合数问题
写着玩玩…… 反正超级sb题. #include<bits/stdc++.h> typedef long long ll; using namespace std; ll c[][],h[ ...
- BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊 动态树
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2002 题意:加边,删边,查询到根的距离. #include <bits/stdc++ ...
- python的IDLE界面回退代码语句
Alt+P回退到IDLE中之前输入的代码语句 Alt+N可以移至下一个代码语句