http://vjudge.net/contest/view.action?cid=55702#overview

12656 - Almost Palindrome http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4394

先把原串处理成只有小写的,然后枚举每一个位置,可以以它为中心向两边扩展,回文可以是奇数,也可以是偶数,分类讨论,如果两边不一样,那么容量加一,容量小于k都行。

  1. #include<cstdio>
  2. #include<cctype>
  3. const int M=;
  4. char a[M],b[M];
  5. int p[M];
  6. int main(){
  7. int n,cas=;
  8. while(~scanf("%d",&n)){
  9. getchar();
  10. gets(a);
  11. int lb=;
  12. for(int i=;a[i];i++){
  13. if(isalpha(a[i])){
  14. p[lb]=i;
  15. b[lb++]=tolower(a[i]);
  16. }
  17. }
  18. int big=,id;
  19. for(int i=;i<lb;i++){
  20. int cnt=;
  21. for(int j=;i-j>=&&i+j<lb;j++){///奇数
  22. if(b[i-j]!=b[i+j]) cnt++;
  23. if(cnt>n) break;
  24. int prelen=p[i+j]-p[i-j]+;
  25. if(big<prelen){
  26. big=prelen;
  27. id=p[i-j];
  28. }
  29. }
  30. cnt=;
  31. for(int j=;i-j>=&&i+j+<lb;j++){///偶数
  32. if(b[i-j]!=b[i+j+]) cnt++;
  33. if(cnt>n) break;
  34. int prelen=p[i+j+]-p[i-j]+;
  35. if(big<prelen){
  36. big=prelen;
  37. id=p[i-j];
  38. }
  39. }
  40. }
  41. printf("Case %d: %d %d\n",cas++,big,id+);
  42. }
  43. return ;
  44. }

12658 - Character Recognition?  http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4396

123识别,找不同。

  1. #include<cstdio>
  2. char a[][];
  3. int main(){
  4. int n;
  5. while(~scanf("%d",&n)){
  6. for(int i=;i<;i++){
  7. scanf("%s",a[i]);
  8. }
  9. for(int i=,y=;i<n;i++,y+=){
  10. if(a[][y]=='.'){
  11. printf("");
  12. continue;
  13. }
  14. if(a[][y+]=='.'){
  15. printf("");
  16. continue;
  17. }
  18. printf("");
  19. }
  20. puts("");
  21. }
  22. return ;
  23. }

12661 - Funny Car Racing http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4399

bfs,记忆化搜索dp,注意t>a的边就别加了

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<queue>
  4. #define mt(a,b) memset(a,b,sizeof(a))
  5. using namespace std;
  6. typedef long long LL;
  7. const LL inf=0x3f3f3f3f3f3f3f3fLL;
  8. const int M=;
  9. struct G{
  10. struct E{
  11. int v,next,a,b,t;
  12. }e[];
  13. int le,head[M];
  14. void init(){
  15. le=;
  16. mt(head,-);
  17. }
  18. void add(int u,int v,int a,int b,int t){
  19. e[le].v=v;
  20. e[le].a=a;
  21. e[le].b=b;
  22. e[le].t=t;
  23. e[le].next=head[u];
  24. head[u]=le++;
  25. }
  26. }g;
  27. LL dp[M];
  28. queue<int> q;
  29. void bfs(int s){
  30. for(int i=;i<M;i++){
  31. dp[i]=inf;
  32. }
  33. dp[s]=;
  34. while(!q.empty()) q.pop();
  35. q.push(s);
  36. while(!q.empty()){
  37. int u=q.front();
  38. q.pop();
  39. LL pretime=dp[u],cost;
  40. for(int i=g.head[u];~i;i=g.e[i].next){
  41. int v=g.e[i].v;
  42. int a=g.e[i].a;
  43. int b=g.e[i].b;
  44. int t=g.e[i].t;
  45. LL now=pretime%(a+b);
  46. if(now+t<=a){
  47. cost=t;
  48. }
  49. else{
  50. cost=a+b-now+t;
  51. }
  52. cost+=pretime;
  53. if(dp[v]>cost){
  54. dp[v]=cost;
  55. q.push(v);
  56. }
  57. }
  58. }
  59. }
  60. int main(){
  61. int n,m,s,t,cas=;
  62. while(~scanf("%d%d%d%d",&n,&m,&s,&t)){
  63. g.init();
  64. while(m--){
  65. int u,v,a,b,c;
  66. scanf("%d%d%d%d%d",&u,&v,&a,&b,&c);
  67. if(c>a) continue;
  68. g.add(u,v,a,b,c);
  69. }
  70. bfs(s);
  71. printf("Case %d: %lld\n",cas++,dp[t]);
  72. }
  73. return ;
  74. }

12662 - Good Teacher http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4400

简单题 注意细节,最坏情况也就是n^2,预处理出最近的。

  1. #include<cstdio>
  2. #include<cstring>
  3. struct G{
  4. char name[],left[],right[];
  5. int L,R;
  6. }g[];
  7. int main(){
  8. int n,m,q;
  9. while(~scanf("%d",&n)){
  10. for(int i=;i<=n;i++){
  11. scanf("%s",g[i].name);
  12. }
  13. for(int i=;i<=n;i++){
  14. if(g[i].name[]=='?'){
  15. int id=i;
  16. for(int j=i;j<=n;j++){
  17. if(g[j].name[]!='?'){
  18. id=j;
  19. break;
  20. }
  21. }
  22. g[i].R=id-i;
  23. if(id==i) g[i].R=;
  24. strcpy(g[i].right,g[id].name);
  25. id=i;
  26. for(int j=i;j>=;j--){
  27. if(g[j].name[]!='?'){
  28. id=j;
  29. break;
  30. }
  31. }
  32. g[i].L=i-id;
  33. if(id==i) g[i].L=;
  34. strcpy(g[i].left,g[id].name);
  35. }
  36. }
  37. scanf("%d",&m);
  38. while(m--){
  39. scanf("%d",&q);
  40. if(g[q].name[]!='?'){
  41. puts(g[q].name);
  42. continue;
  43. }
  44. if(g[q].L==g[q].R){
  45. printf("middle of %s and %s\n",g[q].left,g[q].right);
  46. continue;
  47. }
  48. if(g[q].L<g[q].R){
  49. for(int i=;i<g[q].L;i++){
  50. printf("right of ");
  51. }
  52. puts(g[q].left);
  53. continue;
  54. }
  55. for(int i=;i<g[q].R;i++){
  56. printf("left of ");
  57. }
  58. puts(g[q].right);
  59. }
  60. }
  61. return ;
  62. }

12663 - High bridge, low bridge http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4401

离线的区间累加和是可以左++右--on处理的,当然如果是线段树树状数组都会多个logn,不好 不好

  1. #include<cstdio>
  2. #include<algorithm>
  3. using namespace std;
  4. const int M=;
  5. int a[M],lazy[M];
  6. int main(){
  7. int n,m,k,cas=;
  8. while(~scanf("%d%d%d",&n,&m,&k)){
  9. for(int i=;i<n;i++){
  10. scanf("%d",&a[i]);
  11. lazy[i]=;
  12. }
  13. sort(a,a+n);
  14. int prehigh=,nowa,nowb;
  15. while(m--){
  16. scanf("%d%d",&nowa,&nowb);
  17. int s=upper_bound(a,a+n,prehigh)-a;
  18. int e=upper_bound(a,a+n,nowa)-a;
  19. lazy[s]++;
  20. lazy[e]--;
  21. prehigh=nowb;
  22. }
  23. int now=,ans=;
  24. for(int i=;i<n;i++){
  25. now+=lazy[i];
  26. if(now>=k) ans++;
  27. }
  28. printf("Case %d: %d\n",cas++,ans);
  29. }
  30. return ;
  31. }

12664 - Interesting Calculator http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4402

听说搜索剪枝能过,因为时限大吧,一开始想二维dp,但是不对,用dp i j 表示第 i 个数在第 j 步到达的最小花费,因为可能一步就加了1,所以第二维也可能达到10^5,完全干不动。   仔细考虑了一下,除了*0这种操作, 其余都会使得当前的数变大。所以当x不等于0时,dp 0 只要1步, 然后从小往大的更新最小费用, 因为除了这种情况 其他的值都是从比自己小的值推过来的。

  1. #include<cstdio>
  2. #include<algorithm>
  3. using namespace std;
  4. typedef long long LL;
  5. const LL inf=0x3f3f3f3f3f3f3f3fLL;
  6. const int M=;
  7. LL dp[M];
  8. int step[M];
  9. int val[][];
  10. int main(){
  11. int x,y,cas=;
  12. while(~scanf("%d%d",&x,&y)){
  13. for(int i=;i<;i++){
  14. for(int j=;j<;j++){
  15. scanf("%d",&val[i][j]);
  16. }
  17. }
  18. for(int i=;i<=y;i++){
  19. dp[i]=inf;
  20. step[i]=0x3f3f3f3f;
  21. }
  22. dp[x]=;
  23. step[x]=;
  24. if(x){
  25. dp[]=val[][];
  26. step[]=;
  27. }
  28. for(int i=;i<y;i++){
  29. for(int j=;j<;j++){
  30. for(int k=;k<;k++){
  31. int next;
  32. if(j==){
  33. next=i*+k;
  34. }
  35. else if(j==){
  36. next=i+k;
  37. }
  38. else{
  39. next=i*k;
  40. }
  41. if(next>y) continue;
  42. LL cost=dp[i]+val[j][k];
  43. if(dp[next]>cost){
  44. dp[next]=cost;
  45. step[next]=step[i]+;
  46. }
  47. else if(dp[next]==cost){
  48. step[next]=min(step[next],step[i]+);
  49. }
  50. }
  51. }
  52. }
  53. printf("Case %d: %lld %d\n",cas++,dp[y],step[y]);
  54. }
  55. return ;
  56. }

12665 - Joking with Fermat's Last Theorem http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4403

a,b在1000就够了,所以可以暴力的去判断

  1. #include<cstdio>
  2. int x,y,cas=;
  3. bool ok(int a){
  4. return a>=x&&a<=y;
  5. }
  6. int main(){
  7. while(~scanf("%d%d",&x,&y)){
  8. int ans=;
  9. for(int i=;i<;i++){
  10. for(int j=;j<;j++){
  11. if(ok(i)&&ok(j)){
  12. int left=i*i*i+j*j*j;
  13. if(left%==){
  14. int c=left/;
  15. if(ok(c)){
  16. ans++;
  17. }
  18. }
  19. }
  20. }
  21. }
  22. printf("Case %d: %d\n",cas++,ans);
  23. }
  24. return ;
  25. }

12667 - Last Blood http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4405

唯一的坑就是如果一个队ac一个题,那要算最早ac的时间。

  1. #include<cstdio>
  2. struct G{
  3. int t,id;
  4. }g[];
  5. char p[],yes[];
  6. bool mat[][];
  7. int main(){
  8. int n,t,m,x,y;
  9. while(~scanf("%d%d%d",&n,&t,&m)){
  10. for(int i=;i<n;i++){
  11. g[i].t=-;
  12. for(int j=;j<=t;j++){
  13. mat[i][j]=false;
  14. }
  15. }
  16. while(m--){
  17. scanf("%d%d%s%s",&x,&y,p,yes);
  18. if(yes[]=='N') continue;
  19. int pp=p[]-'A';
  20. if(mat[pp][y]) continue;
  21. mat[pp][y]=true;
  22. g[pp].t=x;
  23. g[pp].id=y;
  24. }
  25. for(int i=;i<n;i++){
  26. printf("%c ",i+'A');
  27. if(g[i].t!=-){
  28. printf("%d %d\n",g[i].t,g[i].id);
  29. }
  30. else{
  31. puts("- -");
  32. }
  33. }
  34. }
  35. return ;
  36. }

end

nenu contest3的更多相关文章

  1. nenu contest3 The 5th Zhejiang Provincial Collegiate Programming Contest

    ZOJ Problem Set - 2965 Accurately Say "CocaCola"!  http://acm.zju.edu.cn/onlinejudge/showP ...

  2. nenu contest2

    http://vjudge.net/vjudge/contest/view.action?cid=54562#overview H  B. Polygons http://codeforces.com ...

  3. nenu contest

    http://vjudge.net/vjudge/contest/view.action?cid=54393#overview A n^2能过 对第二个n我二分了一下,快了一点点,nlogn #inc ...

  4. contest3 CF994 div2 ooxxx? oooox? ooooo?

    题意 div2 C (x)(o) 在一个平面上, 给一个水平的正方形和一个\(45^.斜\)的正方形 求是否相交(共点也算), 坐标正负\(100\)以内 div2 D (x)(o) \(A,B\)两 ...

  5. kgcd ,fmod,fgcd

    参考:NENU CS ACM模板made by tiankonguse  2.13 GCD 快速gcd: 位操作没学,真心不懂二进制,还是得学啊 code: int kgcd(){ if(!a || ...

  6. 嵌入式linux移植LAMP服务器

    一.工具准备工作  要想在ARM平台上移植一套Apache+Msql+PHP的Web型服务器. 所用物理机系统: Ubuntu 14.04 LTS(64位) 交叉编译环境:   arm-linux-g ...

  7. IOS平台设计规范

    一.UI的控件概述: 1.框架UI的元素分为4类: A:栏:状态栏目和导航栏的结合体; B:内容视图:应用显示的内容信息,包括相关的交互行为,例如滚屏.插入.删除等操作进行排序; C:控制元素:产品行 ...

  8. 再识C中的结构体

    在前面认识C中的结构体中我介绍了结构体的基础知识,下面通过这段代码来回顾一下: #include<stdio.h> #define LEN 20 struct Student{ //定义结 ...

  9. PVPGN 暗黑破坏神2 1.11b战网配置问题汇总

    写了第一篇配置指南之后,很多人向我咨询有关战网搭建的问题.于是觉得很有必要把若干常见的问题,和常用的进阶配置汇总一下,以方便更多人. 1.游戏版本和PVPGN与D2GS版本的问题. PVPGN建议选择 ...

随机推荐

  1. atoi 实现

    int atoi(const char *nptr); 把字符串转换成整型数.ASCII to integer 的缩写. 头文件: #include <stdlib.h> 参数nptr字符 ...

  2. 2015.1写留言板的时用的 知识点和函数 --->总结

    一:时间函数和uniqid() 1:uniqid():生成唯一的id, 无参数返回的字符串的长度为13,有参数为23 2:时间和时间戳相互转换的php函数 ①:time()  返回当前unix的时间戳 ...

  3. jQuery增加删除修改tab导航特效

    HTML:         <div class="container iden_top">                <ul>             ...

  4. 设置Linux时间 同步时间

    date命令将日期设置为2014年6月18日 ----   date -s 06/18/14 将时间设置为14点20分50秒 ----   date -s 14:20:50 将时间设置为2014年6月 ...

  5. iis 下的 selfssl

    当然,如果你想省掉所有这些麻烦也行,最简单的在IIS启动SSL的方法只要3步: 1. 下载 IIS 6.0 Resource Kit Tools: http://www.microsoft.com/d ...

  6. easyui获取一行数据和修改data-options的值

    <table id="tab" class="easyui-datagrid" style="width: 100%; height: 500p ...

  7. 原始套接字的简单tcp包嗅探

    原始套接字 sock_raw = socket(AF_INET , SOCK_RAW , IPPROTO_TCP); while(1) { data_size = recvfrom(sock_raw ...

  8. Json(2)-DataContractJsonSerializer

    public static void DataContractSerializeDemo()        {            User user = new User { UserID = 1 ...

  9. Winform上传下载文件代码

    using System; using System.Collections.Generic; using System.Text; using System.Net; using System.IO ...

  10. Microsoft Access Database Engine 2010 Redistributable Download

    SQL Server 如需要导出类似Excel(*.xls.*.xlsx)格式的数据需要以来以下安装包 Microsoft Access 2010 数据库引擎可再发行程序包 此下载将安装一系列组件,帮 ...