8-18-小练

A.HDU 1172   猜数字

采用枚举~【赤果果的暴力~】

代码:

 #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; int x[],y[],s,ss,vis[],dis[];
char a[][]; void find(int b,int c)
{
if(b==(a[c][]-'') && !vis[])
{
s++;vis[]=;
return;
}
if(b==(a[c][]-'') && !vis[])
{
s++;vis[]=;
return;
}
if(b==(a[c][]-'') && !vis[])
{
s++;vis[]=;
return;
}
if(b==(a[c][]-'') && !vis[])
{
s++;vis[]=;
return;
}
} int main()
{
int n,i,j,A,B,C,D,AA,BB,CC,DD;
while(scanf("%d",&n),n)
{
for(i=;i<n;i++)
scanf("%s%d%d",a[i],&x[i],&y[i]);
int sum=;
for(i=;i<=;i++)
{
D=i%;
C=(i/)%;
B=(i/)%;
A=i/;
int k=;
for(j=;j<n;j++)
{
s=,ss=;
memset(vis,,sizeof(vis));
memset(dis,,sizeof(dis));
if(A==a[j][]-'') {ss++;s++;vis[]=;dis[]=;}
if(B==a[j][]-'') {ss++;s++;vis[]=;dis[]=;}
if(C==a[j][]-'') {ss++;s++;vis[]=;dis[]=;}
if(D==a[j][]-'') {ss++;s++;vis[]=;dis[]=;}
if(ss!=y[j]) break;
if(!dis[]) find(A,j);
if(!dis[]) find(B,j);
if(!dis[]) find(C,j);
if(!dis[]) find(D,j);
if(s!=x[j]) break;
k++;
}
if(k==n)
{
sum++;
if(sum==) break;
AA=A;BB=B;CC=C;DD=D;
}
}
if(sum!=) printf("Not sure\n");
else
printf("%d%d%d%d\n",AA,BB,CC,DD);
}
return ;
}

B.HDU 2112     HDU Today

就是字符串处理麻烦了点~将字符串编号+Dijkstra就可以了~

代码:

 #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; #define inf 0x3f3f3f3f //手抽~最开始把inf写的太大了,结果超int了......= =
int map[][],vis[],n,m,s,e;
long dis[];
char name[][]; void dijkstra()
{
memset(vis,,sizeof(vis));
memset(dis,inf,sizeof(dis));
dis[s]=;
for(int i=;i<=m;i++)
{
int x,minn=inf;
for(int j=;j<=m;j++)
if(!vis[j] && dis[j]<minn)
{
minn=dis[j];
x=j;
}
vis[x]=;
for(int y=;y<=m;y++)
dis[y]=min(dis[y],map[x][y]+dis[x]);
}
return;
} int find(char str[])
{
int i;
for(i=;i<=m;i++)
if(strcmp(name[i],str)==)
return i;
if(m== || i>m)
{
m++;
strcpy(name[m],str);
return m;
}
} int main()
{
while(scanf("%d",&n)!=EOF)
{
if(n==-) break;
char start[],end[],s1[],s2[];
int i,j,a,b,c;
scanf("%s%s",start,end);
memset(map,inf,sizeof(map));
m=;
for(i=;i<=n;i++)
{
scanf("%s%s%d",s1,s2,&c);
a=find(s1);
b=find(s2);
if(map[a][b]>c)
map[a][b]=map[b][a]=c;
}
s=find(start);
e=find(end);
if(s==e) printf("0\n");
else
{
dijkstra();
if(dis[e]!=inf)
printf("%ld\n",dis[e]);
else
printf("-1\n");
}
}
return ;
}

//memory:396KB     time:687ms

C.POJ 1321      棋盘问题

dfs~还有就是要注意当K<n 时~

代码:

 #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; bool chess[][],vis[];
int ans,n,k; void dfs(int row,int num)
{
if(num==k){ans++;return;}
if(row>=n) return;
for(int i=;i<n;i++)
if(!vis[i] && chess[row][i])
{
vis[i]=true;
dfs(row+,num+);
vis[i]=false;
}
dfs(row+,num); //这一步很重要~
return;
} int main()
{
while(~scanf("%d%d",&n,&k))
{
if(n==- && k==-) break;
int i,j;
memset(chess,false,sizeof(chess));
for(i=;i<n;i++)
for(j=;j<n;j++)
{
char c;
cin>>c;
if(c=='#')
chess[i][j]=true;
}
ans=;
dfs(,);
printf("%d\n",ans);
}
return ;
}

//memory:708KB    time:32ms

E.POJ 3006      Dirichlet's Theorem on Arithmetic Progressions

呃.......就是暴力啦.......

代码:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std; bool juge(int x)
{
for(int i=;i*i<=x;i++)
if(x%i==) return false;
return true;
} int main()
{
int a,b,n,i,j;
while(scanf("%d%d%d",&a,&b,&n),a,b,n)
{
int k=,sum=;
for(i=;;i++)
{
sum=a+i*b;
if(sum> && juge(sum))
k++;
if(k==n) break;
}
printf("%d\n",sum);
}
return ;
}

//memory:164KB     time:250ms

8-18-Exercise的更多相关文章

  1. [未完成]关于Eclipse4RCP书中内容总结

    原文地址http://www.vogella.com/tutorials/EclipseRCP/article.html Table of Contents 1. Eclipse 4 1.1. Wha ...

  2. Delphi XE Starter Essentials 中文目录

    Table of Contents1. Delphi XE Starter IDE 1Delphi and C++Builder ................................... ...

  3. 18 A GIF decoder: an exercise in Go interfaces 一个GIF解码器:go语言接口训练

    A GIF decoder: an exercise in Go interfaces  一个GIF解码器:go语言接口训练 25 May 2011 Introduction At the Googl ...

  4. C - The C Answer (2nd Edition) - Exercise 1-8

    /* Write a program to count blanks, tabs, and newlines. */ #include <stdio.h> /* count blanks, ...

  5. MIT 6.828 JOS学习笔记5. Exercise 1.3

    Lab 1 Exercise 3 设置一个断点在地址0x7c00处,这是boot sector被加载的位置.然后让程序继续运行直到这个断点.跟踪/boot/boot.S文件的每一条指令,同时使用boo ...

  6. Think Python - Chapter 18 - Inheritance

    In this chapter I present classes to represent playing cards, decks of cards, and poker hands.If you ...

  7. James Munkres Topology: Sec 18 Exer 12

    Theorem 18.4 in James Munkres “Topology” states that if a function \(f : A \rightarrow X \times Y\) ...

  8. CMSC 216 Exercise #5

    CMSC 216 Exercise #5 Spring 2019Shell Jr (”Shellito”) Due: Tue Apr 23, 2019, 11:30PM1 ObjectivesTo p ...

  9. 18年10月31日 NOIP模拟赛

    T1.exercise 题解 数据很小直接模拟 代码 #include<iostream> #include<cstdio> #include<cmath> #in ...

  10. day06-codes and exercise in class

    # Author: Ghost # Email: jiaci.liu@gmail.com ''' 1-Review of last week 2-interface class, abstract c ...

随机推荐

  1. java JNI 调试出现的错误

    java JNI 调试出现的错误 ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2JDW ...

  2. 简单方法打包.net程序集脱离framework

    最近业余捣鼓monogame,自然而然就关注到了.net程序脱离framework发布的问题上了, 度娘,谷歌娘 都经过一番查找,无非分为如下几类方法: 1.直接使用mono运行时,附带 bin.li ...

  3. 应该知道的25个非常有用的CSS技巧

    在我们的前端CSS编码当中,经常要设置特殊的字体效果,边框圆角等等,还要考虑兼 容性的问题, CSS网页布局,说难,其实很简单.说它容易,往往有很多问题困扰着新 手,在中介绍了非常多的技巧,这些小技巧 ...

  4. jQuery UI dialog 的使用

    今天用到了客户端的对话框,把 jQuery UI 中的对话框学习了一下. 准备 jQuery 环境 首先,我们创建一个按钮,点击这个按钮的时候,将会弹出一个对话框. 1 <input type= ...

  5. linux运维面试题

    一.有文件file1 1.查询file1 里面空行的所在行号 grep -n "^#" file1 or awk ‗{if($0~/^$/)print NR}‘ file or g ...

  6. Python中文全攻略

    原文链接:http://blog.csdn.net/mayflowers/archive/2007/04/18/1568852.aspx 1.        在Python中使用中文 在Python中 ...

  7. android 开发adb server is out of date 解决方案

    查看到底是哪个端口给占用了 输入红色部分命令 C:\Users\xxxxxx>netstat -ano | findstr "5037" TCP    127.0.0.1:5 ...

  8. [topcoder]FoxAndChess

    http://community.topcoder.com/stat?c=problem_statement&pm=12725&rd=15702 这题比较简单.首先所有的LR的顺序要一 ...

  9. Java集合类之HashMap

    package com.test; import java.util.*; public class Demo7_3 { public static void main(String[] args) ...

  10. oracle database resident connection pooling(驻留连接池)

    oracle在11g中引入了database resident connection pooling(DRCP).在此之前,我们可以使用dedicated 或者share 方式来链接数据库,dedic ...