数论专场。。。sign。。。。今天看来又要掉分了
Mashmokh works in a factory. At the end of each day he must turn off all of the lights.
The lights on the factory are indexed from 1 to n. There are n buttons in Mashmokh's room indexed from 1 to n as well. If Mashmokh pushes button with index i, then each light with index not less than i that is still turned on turns off.
Mashmokh is not very clever. So instead of pushing the first button he pushes some of the buttons randomly each night. He pushed mdistinct buttons b1, b2, ..., bm (the buttons were pushed consecutively in the given order) this night. Now he wants to know for each light the index of the button that turned this light off. Please note that the index of button bi is actually bi, not i.
Please, help Mashmokh, print these indices.
The first line of the input contains two space-separated integers n and m (1 ≤ n, m ≤ 100), the number of the factory lights and the pushed buttons respectively. The next line contains m distinct space-separated integers b1, b2, ..., bm (1 ≤ bi ≤ n).
It is guaranteed that all lights will be turned off after pushing all buttons.
Output n space-separated integers where the i-th number is index of the button that turns the i-th light off.
5 4 4 3 1 2
1 1 3 4 4
5 5 5 4 3 2 1
1 2 3 4 5
In the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus button number 4 turned lights 4 and 5 off, button number 3 turned light 3 off and button number 1 turned light 1 and 2 off.
题意:关掉第i号灯时,标号大于等于i的亮着的灯都被关上,问每个灯是因为那个灯而关上的
直接模拟就行
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<ctime>
#include<cctype>
#include<cmath>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define sqr(x) (x)*(x)
#define LL long long
#define INF 0x3f3f3f3f
#define PI 3.14159265358979
#define eps 1e-10
#define mm
using namespace std;
int l[111];
int main()
{
#ifndef ONLINE_JUDGE
freopen("t","r",stdin);
#endif
int n,m,x;
memset(l,0,sizeof(l));
scanf("%d%d",&n,&m);
for (int i=0;i<m;i++)
{
scanf("%d",&x);
for (int j=x;j<=n;j++)
{
if (l[j]==0)
{
l[j]=x;
}
}
}
for (int i=1;i<=n;i++)
{
printf("%d ",l[i]);
}
puts("");
return 0;
}
http://codeforces.com/contest/415/problem/B
题意:老板一天发x张代币券,员工能用它来换大洋,用w张代币券可换[a*w/b](下取整)块大洋,代币券只能当天适用,求换最多大洋时最多能留多少代币券
比如a=3,b=7,x=4时,我最多能换3×4/7=1块大洋,但是我显然用3张代币券就能换1块大洋,所以多的1块就应该被保留
设t为当天最多换得的大洋有t=a*x/b,因为是下取整,有不等式t<=ax/b成立,我们现在只要找一个最小的x使得不等式成立,为了讲变量区分开,设至少用y张代币券换t块大洋,有不等式t<=ay/b成立,化简得y>=bt/a,x-y即所求
注意数据范围a,b,x可达10^9,相乘将达到10^18,所以需要用long long(因为没用long long WA了半个小时)
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<ctime>
#include<cctype>
#include<cmath>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define sqr(x) (x)*(x)
#define LL long long
#define INF 0x3f3f3f3f
#define PI 3.14159265358979
#define eps 1e-10
#define mm
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
freopen("t","r",stdin);
#endif
long long n,a,b,t,y,l,r,mid;
scanf("%I64d%I64d%I64d",&n,&a,&b);
long long x,ans;
for (int i=0;i<n;i++)
{
scanf("%I64d",&x);
t=a*x/b;
if ((t*b)%a==0)
{
y=t*b/a;
}
else
{
y=t*b/a + 1;
}
printf("%I64d ",x-y);
}
puts("");
return 0;
}
http://codeforces.com/contest/415/problem/C
It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh.
In this game Mashmokh writes sequence of n distinct integers on the board. Then Bimokh makes several (possibly zero) moves. On the first move he removes the first and the second integer from from the board, on the second move he removes the first and the second integer of the remaining sequence from the board, and so on. Bimokh stops when the board contains less than two numbers. When Bimokh removes numbers x and y from the board, he gets gcd(x, y) points. At the beginning of the game Bimokh has zero points.
Mashmokh wants to win in the game. For this reason he wants his boss to get exactly k points in total. But the guy doesn't know how choose the initial sequence in the right way.
Please, help him. Find n distinct integers a1, a2, ..., an such that his boss will score exactly k points. Also Mashmokh can't memorize too huge numbers. Therefore each of these integers must be at most 109.
The first line of input contains two space-separated integers n, k (1 ≤ n ≤ 105; 0 ≤ k ≤ 108).
If such sequence doesn't exist output -1 otherwise output n distinct space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
5 2
1 2 3 4 5
5 3
2 4 3 7 1
7 2
-1
gcd(x, y) is greatest common divisor of x and y.
题意:M写下n个不同的数,老板每次取出前两个数字直到不足两个数,每次得分为这两个数字的最大公约数,求老板得分为k时的任意可能的数列
刚才和朋友交流过后瞬间被自己的低智商吓到(快给我块豆腐撞死!!!)
先上我的SB思路:
将k分平分成(n/2)份,多出来的余数再分,这样有n/2-k%(n/2)次得a(a=k/(n/2))分,k%(n/2)次得a+1分.
gcd(x,y)=a,有p1*a=x,p2*a=y,p1,p2互质,当 p1+1=p2时有p1,p2互质,如此构造数列
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<ctime>
#include<cctype>
#include<cmath>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define sqr(x) (x)*(x)
#define LL long long
#define INF 0x3f3f3f3f
#define PI 3.14159265358979
#define eps 1e-10
#define mm 1000000001
using namespace std;
int cnt,a,b,n,k,p,t;
int ans[100001];
int main()
{
#ifndef ONLINE_JUDGE
// freopen("t","r",stdin);
#endif
scanf("%d%d",&n,&k);
if (n==1 && k==0)
{
puts("1\n");
return 0;
}
if (n==1)
{
puts("-1");
return 0;
}
if (n/2 > k)
{
puts("-1");
return 0;
}
cnt=0;
a=k/(n/2);
t=k%(n/2);
p=1;
for (int i=0;i<n/2-t;i++)
{
if ((p+1)*(a)<mm)
{
ans[cnt++]=p*(a);
ans[cnt++]=(p+1)*(a);
p+=2;
}
else
{
puts("-1");
return 0;
}
}
for (int i=0;i<t;i++)
{
if ((p+1)*(a+1)<mm)
{
ans[cnt++]=p*(a+1);
ans[cnt++]=(p+1)*(a+1);
p+=2;
}
else
{
puts("-1");
return 0;
}
}
for (int i=0;i<cnt;i++)
{
printf("%d ",ans[i]);
}
if (n%2==1)
{
printf("%d\n",p*(a+1));
}
printf("\n");
return 0;
}
这么蠢的思路也只有我能想到了。。。
别人的思路:
除了第一组,后面的每组数全都互质,如此只要构造出第一组,后面的直接输出连续的数即可,代码请读者自己实现吧
PS:最新消息:掉了4分。。。。。。