洛谷 P1059明明的随机数 & P1068分数线划定 & P1781宇宙总统

题目:https://www.luogu.org/problemnew/show/P1059

思路:STL中的set使用。

 //#include<bits/stdc++.h>
#include<set>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<cstring>
#include<stack>
#include<algorithm> using namespace std; int n;
int val[];
set<int>sss;
set<int>::iterator iter; int main()
{
scanf("%d", &n);
for(int i = ; i < n; i++){
scanf("%d", &val[i]);
sss.insert(val[i]);
}
printf("%d\n", sss.size());
for(iter = sss.begin(); iter != sss.end(); iter++){
printf("%d ", *iter);
}
cout<<endl; return ;
}

题目:https://www.luogu.org/problemnew/show/P1068

思路:struct排序

 //#include<bits/stdc++.h>
#include<set>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<cstring>
#include<stack>
#include<algorithm> using namespace std; int n, m;
struct p{
int id;
int s;
}peo[]; bool cmp(p a, p b)
{
if(a.s == b.s)return a.id < b.id;
else return a.s > b.s;
} int main()
{
scanf("%d%d", &n, &m);
for(int i = ; i < n; i++){
scanf("%d%d", &peo[i].id, &peo[i].s);
}
sort(peo, peo + n, cmp);
int in = m * 1.5;
int ins = peo[in - ].s, i = in;
while(i < n && peo[i].s == ins){
i++;
in++;
}
printf("%d %d\n", ins, in);
for(int j = ; j < in; j++){
printf("%d %d\n", peo[j].id, peo[j].s);
}
return ;
}

题目:https://www.luogu.org/problemnew/show/P1781

思路:java大数找最大值。【今天仔细一想OI生做大数是不是只能背c++大数模板了???】

 import java.io.EOFException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Scanner; public class Main { static int n;
static public void main(String[] args){
Scanner scan = new Scanner(System.in);
n = scan.nextInt();
int id = 0;
BigInteger mmm = BigInteger.ZERO;
for(int i = 0; i < n; i++){
BigInteger tmp = scan.nextBigInteger();
if(tmp.compareTo(mmm) > 0){
mmm = tmp;
id = i + 1;
}
}
System.out.println(id);
System.out.println(mmm);
scan.close();
}
}
上一篇:codeforces C1. The Great Julya Calendar 解题报告


下一篇:Java实现Mysql数据导入导出