lightoj-1014【枚举】
2017-04-04 11:20
459 查看
题目链接:点击打开链接
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 L piaju's were left (L < Q).
Now you have to find the number of piaju's each contestant ate.
Each case contains two non-negative integers P and L (0 ≤ L < P < 231).
大意:
有C个人,安排了P个吃的,每个人会吃Q个吃的,最后留下L个吃的;求所有可能的Q,从小到大输出,要保证Q>L;
思路:
其实就是求出 P-L 的所有数的约数,然后这个约数 >L 的话就满足;感觉开数组会爆,但是没想到也能过
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<set>
using namespace std;
int p,l;
int main()
{
int t,text=0;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&p,&l);
set<int> a;
p-=l;
for(long long i=1;i*i<=p;i++) // 这里换 long long 就过了,之前 int 一直 tle
{
if(p%i==0)
{
if(i>l)
a.insert(i);
if(p/i>l)
a.insert(p/i);
}
}
printf("Case %d:",++text);
if(a.size()==0)
{
puts(" impossible");
continue;
}
set<int>::iterator it;
// bool flag=0;
for(it=a.begin();it!=a.end();it++)
{
// if(flag)
// printf(" ");
printf(" %d",*it);
// flag=1;
}
puts("");
}
return 0;
}
1014 - Ifter Party
PDF (English) | Statistics | Forum |
Time Limit: 2 second(s) | Memory Limit: 32 MB |
ate Q piaju's and L piaju'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 |
有C个人,安排了P个吃的,每个人会吃Q个吃的,最后留下L个吃的;求所有可能的Q,从小到大输出,要保证Q>L;
思路:
其实就是求出 P-L 的所有数的约数,然后这个约数 >L 的话就满足;感觉开数组会爆,但是没想到也能过
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<set>
using namespace std;
int p,l;
int main()
{
int t,text=0;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&p,&l);
set<int> a;
p-=l;
for(long long i=1;i*i<=p;i++) // 这里换 long long 就过了,之前 int 一直 tle
{
if(p%i==0)
{
if(i>l)
a.insert(i);
if(p/i>l)
a.insert(p/i);
}
}
printf("Case %d:",++text);
if(a.size()==0)
{
puts(" impossible");
continue;
}
set<int>::iterator it;
// bool flag=0;
for(it=a.begin();it!=a.end();it++)
{
// if(flag)
// printf(" ");
printf(" %d",*it);
// flag=1;
}
puts("");
}
return 0;
}
相关文章推荐
- LightOJ - 1014 Ifter Party 暴力枚举因子
- lightoj 1154 - Penguins 【拆点建图后枚举汇点 满流判可行解】
- LightOJ 1167 - Dangerous Tunnels 二分枚举+最大流
- Lightoj 1014 - Ifter Party
- LightOJ 1372 (枚举 + 树状数组)
- LightOJ 1407 - Explosion(2sat+枚举)
- hdu 1014 Uniform Generator(水 枚举 gcd)
- lightoj 1014 求一个数的所有因子
- LightOJ 1014 - Ifter Party (**求因子)
- Lightoj 1100 - Again Array Queries (枚举剪枝)
- 51nod oj 1256 1119 1013 1083 1014 1081<组合数+逆元+快速幂,DP,枚举,树状数组>
- LightOJ 1014 Ifter Party 分解因子
- lightoj 1014
- Ifter Party LightOJ - 1014(暴力枚举+set)
- 1014 X^2 Mod P(数论 枚举)(2级算法题)
- LightOJ - 1259 Goldbach`s Conjecture【素数筛+枚举】
- lightoj 1014
- lightoj 1235 Coin Change (IV)(折半枚举)
- lightoj 1014 数论
- Lightoj1014【基础题】