uva-10474-枚举-水题
题意:看代码
#include<stdio.h>
#include<iostream>
#include<sstream>
#include<queue>
#include<map>
#include<memory.h>
#include <math.h>
#include<time.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define N 12000
int a[N];
int n, m; void sort()
{
for(int i = 0; i < n; i++)
for(int j = 1; j < n - i; j++)
if(a[j - 1] > a[j])
{
int t = a[j - 1];
a[j - 1] = a[j];
a[j] = t;
}
}
int find(int k)
{
for(int i = 0; i < n; i++)
{
if(!(a[i] ^ k))
return i;
}
return -1;
}
int sort(const void* a, const void* b)
{
int *pa = (int*) a;
int *pb = (int*) b;
return (*pa) - (*pb);
}
int main(const int argc, char** argv)
{
//freopen("d:\\1.txt", "r", stdin);
int t = 1;
while (scanf("%d %d", &n, &m))
{
if(m == n && n == 0)
return 0;
printf("CASE# %d:\n", t);
t++;
for(int i = 0; i < n; i++)
scanf("%d", a + i);
qsort(a, n, sizeof(int), sort);
int k = 0;
for(int i = 0; i < m; i++)
{
scanf("%d", &k);
int kk = -1;
if((-1 ^ (kk = find(k))))
{
printf("%d found at %d\n", k, kk + 1);
}
else
{
printf("%d not found\n", k);
}
}
} }
冒泡排序。。。时间1.2s
快排。。。时间 390ms
uva-10474-枚举-水题的更多相关文章
- UVa 489 HangmanJudge --- 水题
UVa 489 题目大意:计算机给定一个单词让你猜,你猜一个字母,若单词中存在你猜测的字母,则会显示出来,否则算出错, 你最多只能出错7次(第6次错还能继续猜,第7次错就算你失败),另注意猜一个已经猜 ...
- UVa 1585 Score --- 水题
题目大意:给出一个由O和X组成的串(长度为1-80),统计得分. 每个O的分数为目前连续出现的O的个数,例如,OOXXOXXOOO的得分为1+2+0+0+1+0+0+1+2+3 解题思路:用一个变量t ...
- poj1873 The Fortified Forest 凸包+枚举 水题
/* poj1873 The Fortified Forest 凸包+枚举 水题 用小树林的木头给小树林围一个围墙 每棵树都有价值 求消耗价值最低的做法,输出被砍伐的树的编号和剩余的木料 若砍伐价值相 ...
- UVA 11636-Hello World!(水题,猜结论)
UVA11636-Hello World! Time limit: 1.000 seconds When you first made the computer to print the sentenc ...
- HDU 1017 A Mathematical Curiosity (枚举水题)
Problem Description Given two integers n and m, count the number of pairs of integers (a,b) such tha ...
- COGS 1406. 邻居年龄排序[Age Sort,UVa 11462](水题日常)
★ 输入文件:AgeSort.in 输出文件:AgeSort.out 简单对比时间限制:1 s 内存限制:2 MB [题目描述] Mr.Zero(CH)喜闻乐见地得到了一台内存大大增强 ...
- CodeForces 444C. DZY Loves Physics(枚举+水题)
转载请注明出处:http://blog.csdn.net/u012860063/article/details/37509207 题目链接:http://codeforces.com/contest/ ...
- 方程的解——枚举&&水题
题目 链接 给出方程组:$$\displaystyle \left\{\begin{aligned}11x + 13y + 17z = 2471 \\13x + 17y + 11z = 2739\en ...
- zoj 3809 枚举水题 (2014牡丹江网赛 A题)
题目大意:给出一列取样的几个山的高度点,求山峰有几个? Sample Input 291 3 2 4 6 3 2 3 151 2 3 4 5Sample Output 30 # include < ...
- UVa 12342 Tax Calculator (水题,纳税)
今天在uva看到一个水题,分享一下. 题意:制定纳税的总额,有几个要求,如果第一个180000,不纳,下一个300000,纳10%,再一个400000,纳15%,再一个300000,纳20%,以后的纳 ...
随机推荐
- LeetCode-Microsoft-Clone Graph
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. OJ's ...
- 廖雪峰 ---- Python教程
这是小白的Python新手教程,具有如下特点: 中文,免费,零起点,完整示例,基于最新的Python 3版本. Python是一种计算机程序设计语言.你可能已经听说过很多种流行的编程语言,比如非常难学 ...
- Linux下载
免费下载地址在 http://linux.linuxidc.com/ 用户名与密码都是www.linuxidc.com 下载方法见 http://www.linuxidc.com/Linux/2013 ...
- 在浏览器中输入一个URL后都发生了什么
这道题目没有所谓的完全的正确答案,这个题目可以让你在任意的一个点深入下去, 只要你对这个点是熟悉的.以下是一个大概流程: 浏览器向DNS服务器查找输入URL对应的IP地址. DNS服务器返回网站的IP ...
- weex 知识点
使用 weex init [project_name] 创建的项目,执行 npm run dev 后,在 public/dist 文件夹里面就生成了两个对应的js,一个是index.web.js, 一 ...
- @Resource、@Autowired、@Qualifier 区别(表格显示)
@Resource.@Autowired.@Qualifier 区别(表格显示) 区别项 @Resource @Autowired @Qualifier 谁提供的 jdk提供,包是javax.anno ...
- TopCoder客户端安装
参考:https://blog.csdn.net/github_39353095/article/details/76165940 首先,下载 Java 环境. https://www.java.co ...
- 对比两个表中,字段名不一样的SQL
需要包括有几种情况一.A表中有的字段B表无二.B表有的A表无三.两个表字段名不一致的 --------------------------------------------------------- ...
- Android NDK R9 安装配置 无需Cygwin
转自:http://www.cr173.com/soft/66623.html NDK是一个工具集,可让您实现您的应用程序使用本机代码的语言,如C和C + +.Android NDK 是在SDK前面又 ...
- 2013-8-6 ubuntu基本操作
1,apt-get下载文件默认安装路径 apt-get 下载后,软件所在路径是什么?? /var/cache/apt/archives ubuntu 默认的PATH为 PATH=/home/brigh ...