Problem A. Missing Runners

2018 Fall Waterloo ACM Local Contest
Waterloo, Canada, September 30, 2018
Problem A. Missing Runners

You are organizing a marathon with N runners. Every runner is given a distinct number from 1 to N, so
they can be easily identified.
You record the number of each runner as they cross the finish line. Unfortunately, you notice that only
N − 1 runners have finished. Which runner is still out there?
Input
The first line of input contains the integer N (1 ≤ N ≤ 2
15). The next line contains N −1 distinct integers
in the range from 1 to N, representing the numbers of runners who have crossed the finish line.
Output
Output the number of the runner who has not crossed the finish line.
Example
standard input standard output
5
1 5 2 3
4

  1. 这道题要小心的是数据,2 ^15,数其实并不是很大,一开始我没注意,很麻烦
    2.第二点,就是这道题的思路了,将全部加起来再减去提到的,就是没有提到的
#include<cstdio>
#include<iostream>
#include<cstdio>
#include<map>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a,sum,num;
int main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	sum+=i;
	for(int i=1;i<=n-1;i++){
		scanf("%lld",&a);
		num+=a;
	}
	printf("%lld\n",sum-num);
	return 0;
}
上一篇:Unittest用例管理


下一篇:google浏览器Chrome小恐龙