zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 17

    A. k-th divisor
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    You are given two integers n and k. Find k-th smallest divisor of n, or report that it doesn't exist.

    Divisor of n is any such natural number, that n can be divided by it without remainder.

    Input

    The first line contains two integers n and k (1 ≤ n ≤ 1015, 1 ≤ k ≤ 109).

    Output

    If n has less than k divisors, output -1.

    Otherwise, output the k-th smallest divisor of n.

    Examples
    Input
    4 2
    Output
    2
    Input
    5 3
    Output
    -1
    Input
    12 5
    Output
    6
    Note

    In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2.

    In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1.

     1 #include <bits/stdc++.h>
     2 #define ll long long int
     3 #define N 1000005
     4 #define mem(a) memset(a,0,sizeof(a))
     5 ll k[N];
     6 using namespace std;
     7 ll n;
     8 int m;
     9 set<ll> s;
    10 int main(){
    11   cin>>n>>m;
    12   int cnt=sqrt(n);
    13   for(int i=1;i<=cnt;i++){
    14     if(n%i==0){
    15       s.insert(i);
    16       s.insert(n/i);
    17     }
    18   }
    19   set<ll>::iterator it;
    20   bool prime=true;
    21   for(it=s.begin();it!=s.end();it++){
    22     m--;
    23     if(m==0){
    24       cout<<*it<<endl;
    25       prime=false;
    26       break;
    27     }
    28   }
    29   if(prime)
    30     cout<<-1<<endl;
    31   return 0;
    32 }

     

     

    B. USB vs. PS/2
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis!

    The computers bought for the room were different. Some of them had only USB ports, some — only PS/2 ports, and some had both options.

    You have found a price list of a certain computer shop. In it, for m mouses it is specified the cost and the type of the port that is required to plug the mouse in (USB or PS/2). Each mouse from the list can be bought at most once.

    You want to buy some set of mouses from the given price list in such a way so that you maximize the number of computers equipped with mouses (it is not guaranteed that you will be able to equip all of the computers), and in case of equality of this value you want to minimize the total cost of mouses you will buy.

    Input

    The first line contains three integers a, b and c (0 ≤ a, b, c ≤ 105)  — the number of computers that only have USB ports, the number of computers, that only have PS/2 ports, and the number of computers, that have both options, respectively.

    The next line contains one integer m (0 ≤ m ≤ 3·105)  — the number of mouses in the price list.

    The next m lines each describe another mouse. The i-th line contains first integer vali (1 ≤ vali ≤ 109)  — the cost of the i-th mouse, then the type of port (USB or PS/2) that is required to plug the mouse in.

    Output

    Output two integers separated by space — the number of equipped computers and the total cost of the mouses you will buy.

    Example
    Input
    2 1 1
    4
    5 USB
    6 PS/2
    3 PS/2
    7 PS/2
    Output
    3 14
    Note

    In the first example you can buy the first three mouses. This way you will equip one of the computers that has only a USB port with a USB mouse, and the two PS/2 mouses you will plug into the computer with PS/2 port and the computer with both ports.

     

     1 #include <bits/stdc++.h>
     2 #define ll long long int
     3 #define N 300050
     4 using namespace std;
     5 multiset<ll> c,t,r;
     6 ll  n,m,k,s;
     7 ll x;
     8 ll inde;
     9 string st;
    10 int main(){
    11   cin>>n>>m>>k>>s;
    12   while(s--){
    13     cin>>x>>st;
    14     if(st[0]=='U'){
    15       c.insert(x);
    16     }else{
    17       t.insert(x);
    18     }
    19   }
    20   multiset<ll>::iterator it;
    21   ll cnt=0;
    22   for(it=c.begin();it!=c.end();it++){
    23     if(n){
    24       cnt+=*it;
    25       inde++;
    26       n--;
    27     }else{
    28       r.insert(*it);
    29     }
    30   }
    31   for(it=t.begin();it!=t.end();it++){
    32     if(m){
    33       cnt+=*it;
    34       inde++;
    35       m--;
    36     }else{
    37       r.insert(*it);
    38     }
    39   }
    40   for(it=r.begin();it!=r.end();it++){
    41     if(k){
    42       cnt+=*it;
    43       inde++;
    44       k--;
    45     }
    46   }
    47   cout<<inde<<" "<<cnt<<endl;
    48   return 0;
    49 }

     

  • 相关阅读:
    正则表达式体会
    checkbox、全选反选,获取值
    弹出窗体值回调
    页面点击任意js事件,触发360、IE浏览器新页面
    XML增、删、改
    面试题
    行列转换
    DataTable 和Json 字符串互转
    前台js与后台方法互调
    文件与base64二进制转换
  • 原文地址:https://www.cnblogs.com/zllwxm123/p/7630100.html
Copyright © 2011-2022 走看看