# pf第四次程序大赛

http://acm.pku.cn/JudgeOnline/showproblem?problem_id=1745

17 + 5 + -21 + 15 = 16
17 + 5 + -21 - 15 = -14
17 + 5 - -21 + 15 = 58
17 + 5 - -21 - 15 = 28
17 - 5 + -21 + 15 = 6
17 - 5 + -21 - 15 = -24
17 - 5 - -21 + 15 = 48
17 - 5 - -21 - 15 = 18

while(scanf("%d%d", &n, &k) == 2)
{
/* ...读取n个数据，处理，输出 */
}

while(cin>>n)
{
cin>>k;
// ...读取n个数据，处理，输出
}

--

1 楼

 #include //动态规划#define MAX1 100#define MAX2 10000int main(){    int a[MAX1]={0},n,k;    while(cin >> n >> k)    {        int temp;        cin >> temp;        a[(temp+MAX2*k)%k]=1;        while(--n)        {            int b[MAX1]={0};            cin >> temp;            for(int i=0;i

14 楼

 改进一下:#include#includeint a[10000];int N, K;int solve(int s, int i);int main(void){    int i, flag;           while(1)    {        printf("/ninput N and K, 0, 0 to quit:/n");        scanf("%d%d", &N, &K);        fflush(stdin);                if(N == 0 && K ==0)            break;            printf("input the data:/n");        for(i=0; i
 此帖被评10分

#include <iostream.h>

#define maxnum 10000
#define maxmod 100

void main()
{
int n,k,*pdata,len,modmask,i,j;

int  tmpmod[maxmod] = {0};
int  mod[maxmod]    = {0};

while(cin >> n >> k)
{
modmask = maxnum * k;

pdata = new int[n];

pdata[0] = 0;
pdata[1] = 0;

len = 0;
for (i = 0; i < n; i++)
{
cin >> pdata[len];
if (pdata[len] % k != 0) len++;
}
n = len > 2 ? len : 2;

mod[0] = (pdata[0] + modmask) % k;

len = 1;
for (j = 1; j < n - 1; j++)
{
char used[maxmod] = {1};

int mod1   = 0;
int mod2   = 0;
int tmplen = 0;

for (i = 0; i < len; i++)
{
mod1 = (mod[i] + pdata[j] + modmask) % k ;
mod2 = (mod[i] - pdata[j] + modmask) % k ;

if (!used[mod1]) { tmpmod[tmplen++] = mod1; used[mod1] = 1; }
if (!used[mod2]) { tmpmod[tmplen++] = mod2; used[mod2] = 1; }
}
for (i = 0 ; i < tmplen; i++) mod[i] = tmpmod[i];
len = tmplen;
}

for (i = 0 ; i < len; i++)
if ( ((mod[i] + pdata[n - 1]) % k == 0) || ((mod[i] - pdata[n - 1]) % k == 0) )
{  cout << "Divisible" << endl; break; }

if (i >= len)
cout << "Not divisible" << endl;

delete []pdata;
}
}

• 本文已收录于以下专栏：

举报原因： 您举报文章：pf第四次程序大赛 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)