记录下一开始写错的两道水题

E:

先建出直径,然后在保证直径不变的情况下按照最大度数贪心就好了

注意一下一开始的特判

  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. #define X first
  5. #define Y second
  6. typedef pair<int,int> P;
  7. int n,d,k,tot;vector<P> res;
  8.  
  9. void print()
  10. {
  11. puts("YES");
  12. for(int i=;i<res.size();i++)
  13. printf("%d %d\n",res[i].X,res[i].Y);
  14. }
  15.  
  16. void dfs(int u,int v,int dist,int idx)
  17. {
  18. if(u) res.push_back(P(u,v));
  19. if(tot==n) print(),exit();
  20. if(!dist) return;
  21. for(int i=;i<=idx;i++)
  22. dfs(v,++tot,dist-,k-);
  23. }
  24.  
  25. int main()
  26. {
  27. scanf("%d%d%d",&n,&d,&k);
  28. if(n<=d||n>&&k<) return puts("NO");
  29. for(int i=;i<=d;i++) res.push_back(P(i,i+));
  30. tot=d+;if(tot==n) return print(),;
  31. for(int i=;i<=d;i++)
  32. if(tot<n&&k>) dfs(,i,min(i-,d-i+),k-);
  33. puts("NO");
  34. return ;
  35. }

Problem E

F:

又双叒叕看错题目了,可以缩减多个相同的串……

一开始写的$KMP$,后来发现直接字符串$Hash$就能水过了

注意:此题用$ab$串卡自然溢出,一共只有300个因此单模数就能过

数据开头$dont hash with overflow$好评!

  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. typedef unsigned long long ull;
  5. typedef pair<int,int> P;
  6.  
  7. const int MAXN=;
  8. ull hs[MAXN],MOD=;char s[];
  9. int n,res,tot,len,pre[MAXN];
  10.  
  11. ull cal_hash()
  12. {
  13. ull ret=;
  14. for(int i=;i<strlen(s);i++)
  15. ret=(ret*+(s[i]-'a'+))%MOD;
  16. return ret;
  17. }
  18.  
  19. int main()
  20. {
  21. scanf("%d",&n);
  22. for(int i=;i<=n;i++)
  23. {
  24. scanf("%s",s);int len=strlen(s);
  25. tot+=len;pre[i]=pre[i-]+len;hs[i]=cal_hash();
  26. }
  27. tot+=n-;
  28.  
  29. for(int i=;i<=n;i++)
  30. for(int j=i;j<=n;j++)
  31. {
  32. int cnt=;
  33. for(int k=j+;k+j-i<=n;k++)
  34. {
  35. bool f=true;
  36. for(int l=;l<=j-i;l++)
  37. if(hs[i+l]!=hs[k+l]) f=false;
  38. if(f) cnt++,k+=j-i;
  39. }
  40. if(cnt>) res=max(res,(pre[j]-pre[i-]-)*cnt);
  41. }
  42. printf("%d",tot-res);
  43. return ;
  44. }

Problem F

[Codeforces #494] Tutorial的更多相关文章

  1. [Codeforces #172] Tutorial

    Link: Codeforces #172 传送门 A: 一眼看上去分两类就可以了 1.每个矩形只有两条边相交,重合的形状为菱形 2.每个矩形四条边都有相交 对于情况1答案为$h*h/sin(a)$ ...

  2. [Codeforces #514] Tutorial

    Link: Codeforces #514 传送门 很简单的一场比赛打崩了也是菜得令人无话可说…… D: 一眼二分,发现对于固定的半径和点,能包含该点的圆的圆心一定在一个区间内,求出区间判断即可 此题 ...

  3. [Codeforces #210] Tutorial

    Link: Codeforces #210 传送门 A: 贪心,对每个值都取最大值,不会有其他解使答案变优 #include <bits/stdc++.h> using namespace ...

  4. [Codeforces #196] Tutorial

    Link: Codeforces #196 传送门 A: 枚举 #include <bits/stdc++.h> using namespace std; #define X first ...

  5. [Codeforces #174] Tutorial

    Link: Codeforces #174 传送门 A: 求原根的个数,有一条性质是原根个数为$\phi(\phi(n))$,多了一个不会证的性质 如果要确定哪些是原根的话还是要枚举,不过对于每个数不 ...

  6. [Codeforces #190] Tutorial

    Link: Codeforces #190 传送门 A: 明显答案为$n+m-1$且能构造出来 #include <bits/stdc++.h> using namespace std; ...

  7. [Codeforces #211] Tutorial

    Link: Codeforces #211 传送门 一套非常简单的题目,但很多细节都是错了一次才能发现啊…… 还是不能养成OJ依赖症,交之前先多想想corner case!!! A: 模拟,要特判0啊 ...

  8. [Codeforces #192] Tutorial

    Link: Codeforces #192 传送门 前两天由于食物中毒现在还要每天挂一天的水 只好晚上回来随便找套题做做找找感觉了o(╯□╰)o A: 看到直接大力模拟了 但有一个更简便的方法,复杂度 ...

  9. [Codeforces #201] Tutorial

    Link: 传送门 代码量很少的一套思维题 A: 试一试发现最后状态一定是所有$min,max$间$gcd$的倍数 直接判断数量的奇偶性即可 #include <bits/stdc++.h> ...

随机推荐

  1. 【NOIP】提高组2012 国王游戏

    [题意] 恰逢H国国庆,国王邀请n位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右 手上面分别写下一个整数,国王自己也在左.右手上各写一个整数.然后,让这n位大臣排 成一排,国王站在队伍的最前面.排 ...

  2. bzoj 3524 可持久化线段树

    我们可以先离散化,然后建立权值的可持久化线段树,记录每个数出现的次数,对于区间询问直接判断左右儿子的cnt是不是大于(r-k+1)/2,然后递归到最后一层要是还是大于就有,否则不存在. 反思:挺简单一 ...

  3. hdu 1272 小希的迷宫(并查集+最小生成树+队列)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1272 小希的迷宫 Time Limit: 2000/1000 MS (Java/Others)     ...

  4. 实战手工注入某站,mssql注入

    昨天就搞下来的,但是是工具搞得,为了比赛还是抛弃一阵子的工具吧.内容相对简单,可掠过. 报错得到sql语句: DataSet ds2 = BusinessLibrary.classHelper.Get ...

  5. smb windows中使用的文件共享协议(主要用于与windows互通)

    主要是samba服务. SMB协议又成为CIFS(Common Internet File System)协议 samba服务功能: 1文件共享 2打印共享 3加入windows2000/2003/2 ...

  6. Redis 3.0 编译安装

    Redis 3.0 编译安装 http://www.xuchanggang.cn/archives/991.html

  7. 【LOJbeta round1】ZQC的手办

    NOI2012-超级钢琴的升级版. 用线段树维护最小值及其出现位置,接下来就跟超级钢琴一个做法了. #include<bits/stdc++.h> #define N 500010 #de ...

  8. 【NOIP2016】组合数问题

    写着玩玩…… 反正超级sb题. #include<bits/stdc++.h> typedef long long ll; using namespace std; ll c[][],h[ ...

  9. BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊 动态树

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2002 题意:加边,删边,查询到根的距离. #include <bits/stdc++ ...

  10. python的IDLE界面回退代码语句

    Alt+P回退到IDLE中之前输入的代码语句 Alt+N可以移至下一个代码语句