PAT1041 Be Unique

题目:PAT1041

题解:本来我是想放到队列里,每碰到一个和队头相同的,就把队头弹出。本以为最后队头就是结果,然后发现并不适合第二种情况。

   于是还是使用了标记的方法,对输入的数字进行标记。最后输出第一个标记为1的就行。

代码:

  

 1 #include<cstdio>
 2 #include<cstring>
 3 using namespace std;
 4
 5 int num[10005],n,m[100005];
 6 bool f;
 7
 8 int main()
 9 {
10     scanf("%d",&n);
11     f=false;
12
13     memset(num,0,sizeof(num));
14
15     for(int i=0;i<n;i++)
16     {
17         scanf("%d",&m[i]);
18         num[m[i]]++;
19     }
20
21
22     for(int i=0;i<n;i++)
23     {
24         if(num[m[i]]==1)
25         {
26             printf("%d\n",m[i]);
27             f=true;
28             break;
29         }
30     }
31
32     if(!f) printf("None");
33
34     return 0;
35
36 }
时间: 2024-11-06 09:47:19

PAT1041 Be Unique的相关文章

pat1041. Be Unique (20)

1041. Be Unique (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Being unique is so important to people on Mars that even their lottery is designed in a unique way. The rule of winning is simple: one bets on a number chosen fr

unique()函数

unique()是c++里面的一个去重函数,包含在<iostream>中. 该函数将重复的元素移至容器的末尾,返回的为前面的无重复项的尾地址. 由于返回的是地址,所以经常需要转换为数值使用. 比如: 1 int num[10]={1,1,2,2,2,3,4,5,5,5}; 2 int ans=unique(num,num+10)-num; 返回的ans值为5,,前5项为1 2 3 4 5.

[Leetcode] DP-- 467. Unique Substrings in Wraparound String

Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz", so s will look like this: "...zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd....". Now we have another string p. Your job is to find

leetcode笔记:Unique Paths

一. 题目描述 A robot is located at the top-left corner of a m n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish

LeetCode OJ :Unique Binary Search Trees II(唯一二叉搜索树)

题目如下所示:返回的结果是一个Node的Vector: Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For example,Given n = 3, your program should return all 5 unique BST's shown below. 1 3 3 2 1 \ / / / \ 3 2 1 1 3 2 / / \ 2 1 2

LeetCode --- 62. Unique Paths

题目链接:Unique Paths A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (ma

UNIQUE NullAble

一般情况 UNIQUE 不应该出现nullable的 但是如果我们要支持也是有办法的,就是写一个filter. https://msdn.microsoft.com/en-us/library/ms187019.aspx <--参考 right click add New Index 时记得关掉table,打开的话是不允许add的. set 好一般的UNIQUE后, 在filter 加上 ([columnName] IS NOT NULL) 就可以了.

62.Unique Paths (法1递归-动态规划法2数学公式)

A robot is located at the top-left corner of a m x n grid(marked 'Start' in the diagram below). The robot can only move either down or right at any point in time. Therobot is trying to reach the bottom-right corner of the grid (marked 'Finish'in the

ZOJ 2587 Unique Attack 判断最小割是否唯一

很裸的判断最小割是否唯一.判断方法是先做一遍最大流求最小割,然后从源点和汇点分别遍历所有能够到达的点,看是否覆盖了所有的点,如果覆盖了所有的点,那就是唯一的,否则就是不唯一的. #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <climits> #include <string> #include <iostr