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

  • 相关阅读:
    document.body.clientHeight 和 document.documentElement.clientHeight 的区别
    Javascript操作div及其内含对象示例
    面向对象分析设计的经验原则
    翻页控件示例代码
    C#的6种常用集合类示例
    UML基础知识
    重温OSI和TCP/IP网络分层
    设计模式总结
    活用设计模式
    GridView当数据源为空时仍显示表头
  • 原文地址:https://www.cnblogs.com/dll6/p/7229302.html
Copyright © 2011-2022 走看看