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()             返回指向容器最后一个元素的迭代器

  • 相关阅读:
    MS SQL入门基础:SQL数据库中的事务
    MS SQL入门基础:删除数据
    MS SQL入门基础:触发器的高级应用
    MS SQL入门基础:SQL Server 安全性管理的途径
    MS SQL入门基础:权限管理
    MS SQL入门基础:打开游标
    MS SQL入门基础:数据库更新添加数据
    MS SQL入门基础:游标、游标的优点和种类
    MS SQL入门基础:创建和管理视图
    MS SQL入门基础:数据库中的连接查询
  • 原文地址:https://www.cnblogs.com/dll6/p/7229302.html
Copyright © 2011-2022 走看看