例题5-1 大理石在哪儿 UVa10474
来源:互联网 发布:搭讪素人av 知乎 编辑:程序博客网 时间:2024/04/30 12:41
例题5-1 大理石在哪儿 UVa10474
感悟。
1、从网站下载英文原题,重点在看输入输出数据与格式。
2、英文题目看起来比较吃力,配合上输入输出,算是明白意思了。
3、感觉是道菜题,读取数据,冒泡排序,查找,输出,程序就好了。
4、开始编码,很快样例通过,在http://vjudge.NET里提交,Runtime error。
Total no of test cases is less than 65.没说输入数据个数明白了数组开100太小,果断开10000,提交Time limit exceeded
5、菜题卡壳了。多次提交Time limit exceeded后,参考了与本人写法接近的代码http://www.cnblogs.com/terryX/archive/2013/02/09/2909593.html(该文代码提交验证AC),在该博客代码上进行修改,一步一步接近本人代码,提交验证。
6、经过多次验证,才发现奇葩的错误,const int maxn=10000+10;//maxn=10000 Time limit exceeded 改成maxn=10000+10 AC ;
7、到https://uva.onlinejudge.org提交AC。此时2016-11-14 20:30
8、重读一遍英文原题,才明白Be
assured, none of the input numbers are greater than 10000 and none of them are negative.输入的数字个数不大于10000且非负。(而不是数字大小不大于10000且非负)。
9、一道菜题做成这样,真是没想到。
10、做完该题后,专门对sort,lower_bound函数进行了使用,并进入相关源代码进行了查阅,确实用到了模板。
附上AC代码,编译环境Dev-C++4.9.9.2
#include <cstdio>
using namespace std;
const int maxn=10000+10;//maxn=10000 Time limit exceeded 改成maxn=10000+10 AC
int n,q;
int a[maxn],b[maxn];
int main(){
int i,j;
int t;
int kase=0;
while(scanf("%d%d",&n,&q)&&n&&q){
for(i=1;i<=n;i++)//数据读取
scanf("%d",&a[i]);
for(i=1;i<=q;i++)//数据读取
scanf("%d",&b[i]);
for(i=1;i<=n;i++){//冒泡排序 自小到大
for(j=i+1;j<=n;j++){
if(a[i]>a[j]){
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
kase++;
printf("CASE# %d:\n",kase);
for(i=1;i<=q;i++){//查找
for(j=1;j<=n;j++){
if(b[i]==a[j])
break;
}
if(j>n){
printf("%d not found\n",b[i]);
}else{
printf("%d found at %d\n",b[i],j);
}
}
}
return 0;
}
- 例题5-1 大理石在哪儿 UVa10474
- 《算法竞赛入门经典2ndEdition 》例题5-1 大理石在哪儿(Where is the marble?, Uva10474)
- uva10474大理石在哪儿where is the marble?
- 例题:大理石在哪儿(UVa 10474)
- 大理石在哪儿
- UVa 10474 大理石在哪儿
- STL初步:大理石在哪儿?
- C++之大理石在哪儿?
- 算法入门经典:大理石在哪儿
- 例题5-1 UVA 10474 Where is the Marble?大理石在哪?
- 大理石在哪儿?(Stl lower_bound用法)
- 大理石在哪儿 where is the Marble? lower_bound()
- 大理石在哪儿 (排序和查找) UVA
- 大理石在哪儿 where is the Marble?
- 5-1 UVa10474 Where is the Marble?
- UVa 10474 Where is the Marble?(大理石在哪儿)
- 大理石在哪儿(UVa 10474)(排序与检索)
- 10474 - 大理石在哪儿Where is the Marble?(排序+检索)
- Ajax PHP JavaScript MySQL实现简易无刷新在线聊天室
- Android开发-Retrofit-AndroidStudio(二)Json
- 初学easyui
- HttpURLConnection post json 数据接口请求
- mac下xampp出现DocumentRoot must be a directory报错
- 例题5-1 大理石在哪儿 UVa10474
- swift 基本语法(准备工作)
- webpack resolve 解析
- 全排列散列
- 【Mock.js】前端模拟JSON数据
- 第一个程序测试 (1001)
- 用 html5 FileReader 读取本地图片和文本文件
- 关于backgroundColor="red"写法是否正确的解答
- javascript中的惰性求值