zoukankan      html  css  js  c++  java
  • light oj 1014

    1014 - Ifter Party
     

    I have an Ifter party at the 5th day of Ramadan for the contestants. For this reason I have invited C contestants and arranged P piaju's (some kind of food, specially made for Ifter). Each contestant ate Q piaju's and Lpiaju's were left (L < Q).

    Now you have to find the number of piaju's each contestant ate.

    Input

    Input starts with an integer T (≤ 325), denoting the number of test cases.

    Each case contains two non-negative integers P and L (0 ≤ L < P < 231).

    Output

    For each case, print the case number and the number of possible integers in ascending order. If no such integer is found print 'impossible'.

    Sample Input

    Output for Sample Input

    4

    10 0

    13 2

    300 98

    1000 997

    Case 1: 1 2 5 10

    Case 2: 11

    Case 3: 101 202

    Case 4: impossible

    代码:

    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<iostream>
    #include<algorithm>
    #include<vector>


    using namespace std;

    int main(void)
    {
    int T, cas;
    int p, l;
    vector<int>vec;

    scanf("%d", &T);

    cas = 0;

    while(T--)
    {
    cas++;
    vec.clear();

    scanf("%d%d", &p, &l);

    int n = p - l;

    int m =(int)sqrt(n);

    for(int i = 1; i <= m; i++)
    {
    if(n % i == 0)
    {
    if(i > l)
    vec.push_back(i);
    if(i * i != n)
    {
    if(n / i > l)
    vec.push_back(n / i);
    }
    }
    }

    sort(vec.begin(), vec.end());
    printf("Case %d:", cas);

    int mm = vec.size();
    if(mm == 0)
    printf(" impossible ");

    for(int i = 0; i < mm; i++)
    printf(" %d", vec[i]);

    printf(" ");
    }
    return 0;
    }

    c++容器<vector>文件名#include<vector>   定义vector<int>c;

               c.clear()         移除容器中所有数据。

                                 c.empty()         判断容器是否为空。

                                 c.erase(pos)        删除pos位置的数据

                                 c.erase(beg,end) 删除[beg,end)区间的数据

                                 c.front()         传回第一个数据。

                                 c.insert(pos,elem)  在pos位置插入一个elem拷贝

                                 c.pop_back()     删除最后一个数据。

                                 c.push_back(elem) 在尾部加入一个数据。

                                 c.resize(num)     重新设置该容器的大小

                                 c.size()         回容器中实际数据的个数。

                                 c.begin()           返回指向容器第一个元素的迭代器

                                 c.end()             返回指向容器最后一个元素的迭代器

  • 相关阅读:
    CentOS 7 安装MySQL 5.6遇到的疑难杂症小结
    ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'
    MS SQL巡检系列——检查外键字段是否缺少索引
    Linix登录报"/etc/profile: line 11: syntax error near unexpected token `$'{ ''"
    MS SQL巡检系列——检查重复索引
    [转载】——故障排除:Shared Pool优化和Library Cache Latch冲突优化 (文档 ID 1523934.1)
    SQL Server 2014 Database Mail重复发送邮件特殊案例
    ORACLE推导参数Derived Parameter介绍
    SQL SERVER 数据库各版本功能对比
    SQL Server会话KILL不掉,一直处于KILLED /ROLLBACK状态情形浅析
  • 原文地址:https://www.cnblogs.com/dll6/p/7229302.html
Copyright © 2011-2022 走看看