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


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

    思路:STL中的set使用。

     1 //#include<bits/stdc++.h>
     2 #include<set>
     3 #include<iostream>
     4 #include<stdio.h>
     5 #include<stdlib.h>
     6 #include<cstring>
     7 #include<stack>
     8 #include<algorithm>
     9 
    10 using namespace std;
    11 
    12 int n;
    13 int val[105];
    14 set<int>sss;
    15 set<int>::iterator iter;
    16 
    17 int main()
    18 {
    19     scanf("%d", &n);
    20     for(int i = 0; i < n; i++){
    21         scanf("%d", &val[i]);
    22         sss.insert(val[i]);
    23     }
    24     printf("%d
    ", sss.size());
    25     for(iter = sss.begin(); iter != sss.end(); iter++){
    26         printf("%d ", *iter);
    27     }
    28     cout<<endl;
    29 
    30     return 0;
    31 }

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

    思路:struct排序

     1 //#include<bits/stdc++.h>
     2 #include<set>
     3 #include<iostream>
     4 #include<stdio.h>
     5 #include<stdlib.h>
     6 #include<cstring>
     7 #include<stack>
     8 #include<algorithm>
     9 
    10 using namespace std;
    11 
    12 int n, m;
    13 struct p{
    14     int id;
    15     int s;
    16 }peo[5005];
    17 
    18 bool cmp(p a, p b)
    19 {
    20     if(a.s == b.s)return a.id < b.id;
    21     else return a.s > b.s;
    22 }
    23 
    24 int main()
    25 {
    26     scanf("%d%d", &n, &m);
    27     for(int i = 0; i < n; i++){
    28         scanf("%d%d", &peo[i].id, &peo[i].s);
    29     }
    30     sort(peo, peo + n, cmp);
    31     int in = m * 1.5;
    32     int ins = peo[in - 1].s, i = in;
    33     while(i < n && peo[i].s == ins){
    34         i++;
    35         in++;
    36     }
    37     printf("%d %d
    ", ins, in);
    38     for(int j = 0; j < in; j++){
    39         printf("%d %d
    ", peo[j].id, peo[j].s);
    40     }
    41     return 0;
    42 }

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

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

     1 import java.io.EOFException;
     2 import java.math.BigDecimal;
     3 import java.math.BigInteger;
     4 import java.util.Scanner;
     5 
     6 public class Main {
     7 
     8     static int n;
     9     static public void main(String[] args){
    10         Scanner scan = new Scanner(System.in);
    11         n = scan.nextInt();
    12         int id = 0;
    13         BigInteger mmm = BigInteger.ZERO;
    14         for(int i = 0; i < n; i++){
    15             BigInteger tmp = scan.nextBigInteger();
    16             if(tmp.compareTo(mmm) > 0){
    17                 mmm = tmp;
    18                 id = i + 1;
    19             }
    20         }
    21         System.out.println(id);
    22         System.out.println(mmm);
    23         scan.close();
    24     }
    25 }
  • 相关阅读:
    C# 普印力RFID打印机模板打印
    C# IP地址段端口扫描器封装调用
    W3100SMS 短信猫代码发送 下
    C#动态创建Access数据库,创建加密码Access数据库,更改Access密码
    C# 区分键盘和红外线扫描枪输入 模拟扫描枪
    文件格式大全
    winform获取当前Url地址
    [WPF]使用C#代码实现DataTemplate
    钩子类型
    WM_*
  • 原文地址:https://www.cnblogs.com/wyboooo/p/10274465.html
Copyright © 2020-2023  润新知