Error[8]: Undefined offset: 2, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

第一题:小Q系列故事——世界上最遥远的距离

链接 :http://acm.hdu.edu.cn/showproblem.php?pid=4515

题解:由于水题,直接贴roro大牛的代码

#include <stdio.h>
int day[2][13]  = {0,31,28,31,30,31,30,31,31,30,31,30,31,0,31,29,31,30,31,30,31,31,30,31,30,31};

int judge(int y)
{
    if (y%4 == 0 && y % 100 != 0 || y % 400 == 0)
        return 1;
    else
        return 0;
}

int main()
{
    int t, n;
    scanf("%d",&t);
    while (t--)
    {
        int sy = 2013, sm = 3, sd = 24;
        scanf("%d",&n);
        sd += n;
        while (1)
        {
            int y = judge(sy);
            if(sd > day[y][sm])
            {
                sd -= day[y][sm];
                sm += 1;
                if(sm > 12)
                {
                    sm = 1;
                    sy += 1;
                }
            }
            else
                break;
        }
        printf("%4d/%02d/%02d ",sy,sm,sd);
        sy = 2013, sm = 3, sd = 24;
        sd -= n;
        while (1)
        {
            if(sd < 1)
            {
                sm -= 1;
                if(sm < 1)
                {
                    sm = 12;
                    sy -= 1;
                }
                int y = judge(sy);
                sd += day[y][sm];
            }
            else
                break;
        }
        printf("%4d/%02d/%02d\n",sy,sm,sd);
    }
}
第二题:威威猫系列故事——因式分解

链接:http://acm.hdu.edu.cn/showproblem.php?pid=4516

题解:(转自大牛http://www.cnblogs.com/Lyush/archive/2013/03/24/2978239.html)

题意:给定一个多项式,对其进行因式分解。

解法:由于多项式每一项系数绝对值不超过1000,由于最后解的形式为(x-a)(x-b)(x-c)(x-d)(x-e)其中a*b*c*d*e一定是最后的常数项系数,因此a, b, c, d, e的取值范围都在[-1000, 1000]内,因此枚举所有的根,剩下的就是重根的时候该怎么办?一个解决办法就是对原多项式进行求导,如果一个根t是f(x)的K重根的话,那么t一定是f(x)'的K-1重根。该题的字符串处理我没写好,后面调了很久。还有就是由于有5次方存在,因此代入时使用long long计算。

#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cctype>
#include <vector>
using namespace std;

char str[500];
int seq[10];

long long _pow(int a, int b) {
    long long ret = 1;
    for (int i = 0; i < b; ++i) {
        ret *= a;
    }
    return ret;
}

int jiechen[10] = {1, 1, 2, 6, 24, 120};

void qiudao(int *rec, int k) {
    for (int i = k; i <= 5; ++i) {
        rec[i-k] = jiechen[i] / jiechen[i-k] * seq[i];
    }
}

bool judge(int rec[], int x) {
    long long sum = 0;
    for (int i = 0; i <= 5; ++i) {
        sum += 1LL * rec[i] * _pow(x, i);
    }
    return sum == 0;
}

void gao(char ts[]) {
    int len = strlen(ts);
    int p = -1, a, b;
    for (int i = 0; i < len; ++i) {
        if (ts[i] == 'x') {
            if (isdigit(ts[i-1])) { 
                ts[i] = '[+++]';
            } else {
                ts[i] = '1';
            }
            p = -2;
        } else if (ts[i] == '^') {
            ts[i] = '[+++]';
            p = i+1;    
        }
    }
    a = atoi(ts);
    if (!a && p != -1) a = 1;
    if (p == -1) {
        b = 0;
    } else if (p == -2) {
        b = 1;
    }else {
        b = atoi(ts+p);
    }
    seq[b] += a;
}

void solve() {
    vector<int>v;
    int cnt = 0;
    memset(seq, 0, sizeof (seq));
    char ts[50], *p;
    p = strtok(str, "+");
    while (p) {
        strcpy(ts, p);
        gao(ts);
        p = strtok(NULL, "+");
    }
    for (int i = 5; i >= 0; --i) {
        if (seq[i] != 0) {
            cnt = i;
            break;
        }
    }
    for (int i = -1000; i <= 1000; ++i) { 
        for (int j = 0; j < cnt; ++j) {
            int rec[10]    = {0};
            qiudao(rec, j);
            if (judge(rec, i)) {
                v.push_back(i);
            } else {
                break;
            }
        }
    }
    //x^4-x^2
    //x^4-7x^3+18x^2-20x+8
    //x^3-13x^2+55x-75
    //x^2+5x^2-6x^2+x^2+2x-20x+30x-10x+8-7
    //x^5-10x^4+39x^3-74x^2+68x-24
    //以上都是能够分解的式子 
    if (v.size() != cnt || seq[cnt] != 1 || cnt == 0) {
        printf("-1\n");
    } else {
        sort(v.begin(), v.end());
        for (int i = v.size()-1; i >= 0; --i) {
            if (v[i] < 0) {
                printf("(x+%d)", -v[i]);
            } else if (v[i] == 0) {
                printf("x");    
            } else {
                printf("(x-%d)", v[i]);    
            }
        }
        puts("");
    }
}

int main() {
    int T, ca = 0;
    scanf("%d", &T);
    while (T--) {
        scanf("%s", str);
        int len = strlen(str);
        for (int i = 0; i < len; ++i) {
            if (str[i] == '-') {
                for (int j = len-1; j >= i; --j) {
                    str[j+1] = str[j];
                }
                str[i] = '+';
                len += 1;
                ++i;
                str[len] = '[+++]';
            }
            
        }
        printf("Case #%d: ", ++ca);
        solve();
    }
    return 0;
}


第三题:小小明系列故事——游戏的烦恼

链接:http://acm.hdu.edu.cn/showproblem.php?pid=4518

题解:(转自网上大牛:http://blog.csdn.net/zhuhuangjian/article/details/8711287)

用p[i][j]存放0~i-1 * 0~j-1里的黑点数目。

然后对枚举,

 

 if(p[i+x-1][j+y-1]+p[i-1][j-1]-p[i+x-1][j-1]-p[i-1][j+y-1]==x*y))
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 3, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

第一题:小Q系列故事——世界上最遥远的距离

链接 :http://acm.hdu.edu.cn/showproblem.php?pid=4515

题解:由于水题,直接贴roro大牛的代码

#include <stdio.h>
int day[2][13]  = {0,31,28,31,30,31,30,31,31,30,31,30,31,0,31,29,31,30,31,30,31,31,30,31,30,31};

int judge(int y)
{
    if (y%4 == 0 && y % 100 != 0 || y % 400 == 0)
        return 1;
    else
        return 0;
}

int main()
{
    int t, n;
    scanf("%d",&t);
    while (t--)
    {
        int sy = 2013, sm = 3, sd = 24;
        scanf("%d",&n);
        sd += n;
        while (1)
        {
            int y = judge(sy);
            if(sd > day[y][sm])
            {
                sd -= day[y][sm];
                sm += 1;
                if(sm > 12)
                {
                    sm = 1;
                    sy += 1;
                }
            }
            else
                break;
        }
        printf("%4d/%02d/%02d ",sy,sm,sd);
        sy = 2013, sm = 3, sd = 24;
        sd -= n;
        while (1)
        {
            if(sd < 1)
            {
                sm -= 1;
                if(sm < 1)
                {
                    sm = 12;
                    sy -= 1;
                }
                int y = judge(sy);
                sd += day[y][sm];
            }
            else
                break;
        }
        printf("%4d/%02d/%02d\n",sy,sm,sd);
    }
}
第二题:威威猫系列故事——因式分解

链接:http://acm.hdu.edu.cn/showproblem.php?pid=4516

题解:(转自大牛http://www.cnblogs.com/Lyush/archive/2013/03/24/2978239.html)

题意:给定一个多项式,对其进行因式分解。

解法:由于多项式每一项系数绝对值不超过1000,由于最后解的形式为(x-a)(x-b)(x-c)(x-d)(x-e)其中a*b*c*d*e一定是最后的常数项系数,因此a, b, c, d, e的取值范围都在[-1000, 1000]内,因此枚举所有的根,剩下的就是重根的时候该怎么办?一个解决办法就是对原多项式进行求导,如果一个根t是f(x)的K重根的话,那么t一定是f(x)'的K-1重根。该题的字符串处理我没写好,后面调了很久。还有就是由于有5次方存在,因此代入时使用long long计算。

#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cctype>
#include <vector>
using namespace std;

char str[500];
int seq[10];

long long _pow(int a, int b) {
    long long ret = 1;
    for (int i = 0; i < b; ++i) {
        ret *= a;
    }
    return ret;
}

int jiechen[10] = {1, 1, 2, 6, 24, 120};

void qiudao(int *rec, int k) {
    for (int i = k; i <= 5; ++i) {
        rec[i-k] = jiechen[i] / jiechen[i-k] * seq[i];
    }
}

bool judge(int rec[], int x) {
    long long sum = 0;
    for (int i = 0; i <= 5; ++i) {
        sum += 1LL * rec[i] * _pow(x, i);
    }
    return sum == 0;
}

void gao(char ts[]) {
    int len = strlen(ts);
    int p = -1, a, b;
    for (int i = 0; i < len; ++i) {
        if (ts[i] == 'x') {
            if (isdigit(ts[i-1])) { 
                ts[i] = '';
            } else {
                ts[i] = '1';
            }
            p = -2;
        } else if (ts[i] == '^') {
            ts[i] = '[+++]';
            p = i+1;    
        }
    }
    a = atoi(ts);
    if (!a && p != -1) a = 1;
    if (p == -1) {
        b = 0;
    } else if (p == -2) {
        b = 1;
    }else {
        b = atoi(ts+p);
    }
    seq[b] += a;
}

void solve() {
    vector<int>v;
    int cnt = 0;
    memset(seq, 0, sizeof (seq));
    char ts[50], *p;
    p = strtok(str, "+");
    while (p) {
        strcpy(ts, p);
        gao(ts);
        p = strtok(NULL, "+");
    }
    for (int i = 5; i >= 0; --i) {
        if (seq[i] != 0) {
            cnt = i;
            break;
        }
    }
    for (int i = -1000; i <= 1000; ++i) { 
        for (int j = 0; j < cnt; ++j) {
            int rec[10]    = {0};
            qiudao(rec, j);
            if (judge(rec, i)) {
                v.push_back(i);
            } else {
                break;
            }
        }
    }
    //x^4-x^2
    //x^4-7x^3+18x^2-20x+8
    //x^3-13x^2+55x-75
    //x^2+5x^2-6x^2+x^2+2x-20x+30x-10x+8-7
    //x^5-10x^4+39x^3-74x^2+68x-24
    //以上都是能够分解的式子 
    if (v.size() != cnt || seq[cnt] != 1 || cnt == 0) {
        printf("-1\n");
    } else {
        sort(v.begin(), v.end());
        for (int i = v.size()-1; i >= 0; --i) {
            if (v[i] < 0) {
                printf("(x+%d)", -v[i]);
            } else if (v[i] == 0) {
                printf("x");    
            } else {
                printf("(x-%d)", v[i]);    
            }
        }
        puts("");
    }
}

int main() {
    int T, ca = 0;
    scanf("%d", &T);
    while (T--) {
        scanf("%s", str);
        int len = strlen(str);
        for (int i = 0; i < len; ++i) {
            if (str[i] == '-') {
                for (int j = len-1; j >= i; --j) {
                    str[j+1] = str[j];
                }
                str[i] = '+';
                len += 1;
                ++i;
                str[len] = '[+++]';
            }
            
        }
        printf("Case #%d: ", ++ca);
        solve();
    }
    return 0;
}


第三题:小小明系列故事——游戏的烦恼

链接:http://acm.hdu.edu.cn/showproblem.php?pid=4518

题解:(转自网上大牛:http://blog.csdn.net/zhuhuangjian/article/details/8711287)

用p[i][j]存放0~i-1 * 0~j-1里的黑点数目。

然后对枚举,

 

 if(p[i+x-1][j+y-1]+p[i-1][j-1]-p[i+x-1][j-1]-p[i-1][j+y-1]==x*y))
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 4, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

第一题:小Q系列故事——世界上最遥远的距离

链接 :http://acm.hdu.edu.cn/showproblem.php?pid=4515

题解:由于水题,直接贴roro大牛的代码

#include <stdio.h>
int day[2][13]  = {0,31,28,31,30,31,30,31,31,30,31,30,31,0,31,29,31,30,31,30,31,31,30,31,30,31};

int judge(int y)
{
    if (y%4 == 0 && y % 100 != 0 || y % 400 == 0)
        return 1;
    else
        return 0;
}

int main()
{
    int t, n;
    scanf("%d",&t);
    while (t--)
    {
        int sy = 2013, sm = 3, sd = 24;
        scanf("%d",&n);
        sd += n;
        while (1)
        {
            int y = judge(sy);
            if(sd > day[y][sm])
            {
                sd -= day[y][sm];
                sm += 1;
                if(sm > 12)
                {
                    sm = 1;
                    sy += 1;
                }
            }
            else
                break;
        }
        printf("%4d/%02d/%02d ",sy,sm,sd);
        sy = 2013, sm = 3, sd = 24;
        sd -= n;
        while (1)
        {
            if(sd < 1)
            {
                sm -= 1;
                if(sm < 1)
                {
                    sm = 12;
                    sy -= 1;
                }
                int y = judge(sy);
                sd += day[y][sm];
            }
            else
                break;
        }
        printf("%4d/%02d/%02d\n",sy,sm,sd);
    }
}
第二题:威威猫系列故事——因式分解

链接:http://acm.hdu.edu.cn/showproblem.php?pid=4516

题解:(转自大牛http://www.cnblogs.com/Lyush/archive/2013/03/24/2978239.html)

题意:给定一个多项式,对其进行因式分解。

解法:由于多项式每一项系数绝对值不超过1000,由于最后解的形式为(x-a)(x-b)(x-c)(x-d)(x-e)其中a*b*c*d*e一定是最后的常数项系数,因此a, b, c, d, e的取值范围都在[-1000, 1000]内,因此枚举所有的根,剩下的就是重根的时候该怎么办?一个解决办法就是对原多项式进行求导,如果一个根t是f(x)的K重根的话,那么t一定是f(x)'的K-1重根。该题的字符串处理我没写好,后面调了很久。还有就是由于有5次方存在,因此代入时使用long long计算。

#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cctype>
#include <vector>
using namespace std;

char str[500];
int seq[10];

long long _pow(int a, int b) {
    long long ret = 1;
    for (int i = 0; i < b; ++i) {
        ret *= a;
    }
    return ret;
}

int jiechen[10] = {1, 1, 2, 6, 24, 120};

void qiudao(int *rec, int k) {
    for (int i = k; i <= 5; ++i) {
        rec[i-k] = jiechen[i] / jiechen[i-k] * seq[i];
    }
}

bool judge(int rec[], int x) {
    long long sum = 0;
    for (int i = 0; i <= 5; ++i) {
        sum += 1LL * rec[i] * _pow(x, i);
    }
    return sum == 0;
}

void gao(char ts[]) {
    int len = strlen(ts);
    int p = -1, a, b;
    for (int i = 0; i < len; ++i) {
        if (ts[i] == 'x') {
            if (isdigit(ts[i-1])) { 
                ts[i] = '';
            } else {
                ts[i] = '1';
            }
            p = -2;
        } else if (ts[i] == '^') {
            ts[i] = '';
            p = i+1;    
        }
    }
    a = atoi(ts);
    if (!a && p != -1) a = 1;
    if (p == -1) {
        b = 0;
    } else if (p == -2) {
        b = 1;
    }else {
        b = atoi(ts+p);
    }
    seq[b] += a;
}

void solve() {
    vector<int>v;
    int cnt = 0;
    memset(seq, 0, sizeof (seq));
    char ts[50], *p;
    p = strtok(str, "+");
    while (p) {
        strcpy(ts, p);
        gao(ts);
        p = strtok(NULL, "+");
    }
    for (int i = 5; i >= 0; --i) {
        if (seq[i] != 0) {
            cnt = i;
            break;
        }
    }
    for (int i = -1000; i <= 1000; ++i) { 
        for (int j = 0; j < cnt; ++j) {
            int rec[10]    = {0};
            qiudao(rec, j);
            if (judge(rec, i)) {
                v.push_back(i);
            } else {
                break;
            }
        }
    }
    //x^4-x^2
    //x^4-7x^3+18x^2-20x+8
    //x^3-13x^2+55x-75
    //x^2+5x^2-6x^2+x^2+2x-20x+30x-10x+8-7
    //x^5-10x^4+39x^3-74x^2+68x-24
    //以上都是能够分解的式子 
    if (v.size() != cnt || seq[cnt] != 1 || cnt == 0) {
        printf("-1\n");
    } else {
        sort(v.begin(), v.end());
        for (int i = v.size()-1; i >= 0; --i) {
            if (v[i] < 0) {
                printf("(x+%d)", -v[i]);
            } else if (v[i] == 0) {
                printf("x");    
            } else {
                printf("(x-%d)", v[i]);    
            }
        }
        puts("");
    }
}

int main() {
    int T, ca = 0;
    scanf("%d", &T);
    while (T--) {
        scanf("%s", str);
        int len = strlen(str);
        for (int i = 0; i < len; ++i) {
            if (str[i] == '-') {
                for (int j = len-1; j >= i; --j) {
                    str[j+1] = str[j];
                }
                str[i] = '+';
                len += 1;
                ++i;
                str[len] = '[+++]';
            }
            
        }
        printf("Case #%d: ", ++ca);
        solve();
    }
    return 0;
}


第三题:小小明系列故事——游戏的烦恼

链接:http://acm.hdu.edu.cn/showproblem.php?pid=4518

题解:(转自网上大牛:http://blog.csdn.net/zhuhuangjian/article/details/8711287)

用p[i][j]存放0~i-1 * 0~j-1里的黑点数目。

然后对枚举,

 

 if(p[i+x-1][j+y-1]+p[i-1][j-1]-p[i+x-1][j-1]-p[i-1][j+y-1]==x*y))
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
[置顶] 2013腾讯编程马拉松初赛第3场(3月23)(HDU 4515 HDU4516 HDU4517 HDU4517 HDU4519)_随笔_内存溢出

[置顶] 2013腾讯编程马拉松初赛第3场(3月23)(HDU 4515 HDU4516 HDU4517 HDU4517 HDU4519)

[置顶] 2013腾讯编程马拉松初赛第3场(3月23)(HDU 4515 HDU4516 HDU4517 HDU4517 HDU4519),第1张

第一题:小Q系列故事——世界上最遥远的距离

链接 :http://acm.hdu.edu.cn/showproblem.php?pid=4515

题解:由于水题,直接贴roro大牛的代码

#include <stdio.h>
int day[2][13]  = {0,31,28,31,30,31,30,31,31,30,31,30,31,0,31,29,31,30,31,30,31,31,30,31,30,31};

int judge(int y)
{
    if (y%4 == 0 && y % 100 != 0 || y % 400 == 0)
        return 1;
    else
        return 0;
}

int main()
{
    int t, n;
    scanf("%d",&t);
    while (t--)
    {
        int sy = 2013, sm = 3, sd = 24;
        scanf("%d",&n);
        sd += n;
        while (1)
        {
            int y = judge(sy);
            if(sd > day[y][sm])
            {
                sd -= day[y][sm];
                sm += 1;
                if(sm > 12)
                {
                    sm = 1;
                    sy += 1;
                }
            }
            else
                break;
        }
        printf("%4d/%02d/%02d ",sy,sm,sd);
        sy = 2013, sm = 3, sd = 24;
        sd -= n;
        while (1)
        {
            if(sd < 1)
            {
                sm -= 1;
                if(sm < 1)
                {
                    sm = 12;
                    sy -= 1;
                }
                int y = judge(sy);
                sd += day[y][sm];
            }
            else
                break;
        }
        printf("%4d/%02d/%02d\n",sy,sm,sd);
    }
}
第二题:威威猫系列故事——因式分解

链接:http://acm.hdu.edu.cn/showproblem.php?pid=4516

题解:(转自大牛http://www.cnblogs.com/Lyush/archive/2013/03/24/2978239.html)

题意:给定一个多项式,对其进行因式分解。

解法:由于多项式每一项系数绝对值不超过1000,由于最后解的形式为(x-a)(x-b)(x-c)(x-d)(x-e)其中a*b*c*d*e一定是最后的常数项系数,因此a, b, c, d, e的取值范围都在[-1000, 1000]内,因此枚举所有的根,剩下的就是重根的时候该怎么办?一个解决办法就是对原多项式进行求导,如果一个根t是f(x)的K重根的话,那么t一定是f(x)'的K-1重根。该题的字符串处理我没写好,后面调了很久。还有就是由于有5次方存在,因此代入时使用long long计算。

#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cctype>
#include <vector>
using namespace std;

char str[500];
int seq[10];

long long _pow(int a, int b) {
    long long ret = 1;
    for (int i = 0; i < b; ++i) {
        ret *= a;
    }
    return ret;
}

int jiechen[10] = {1, 1, 2, 6, 24, 120};

void qiudao(int *rec, int k) {
    for (int i = k; i <= 5; ++i) {
        rec[i-k] = jiechen[i] / jiechen[i-k] * seq[i];
    }
}

bool judge(int rec[], int x) {
    long long sum = 0;
    for (int i = 0; i <= 5; ++i) {
        sum += 1LL * rec[i] * _pow(x, i);
    }
    return sum == 0;
}

void gao(char ts[]) {
    int len = strlen(ts);
    int p = -1, a, b;
    for (int i = 0; i < len; ++i) {
        if (ts[i] == 'x') {
            if (isdigit(ts[i-1])) { 
                ts[i] = '';
            } else {
                ts[i] = '1';
            }
            p = -2;
        } else if (ts[i] == '^') {
            ts[i] = '';
            p = i+1;    
        }
    }
    a = atoi(ts);
    if (!a && p != -1) a = 1;
    if (p == -1) {
        b = 0;
    } else if (p == -2) {
        b = 1;
    }else {
        b = atoi(ts+p);
    }
    seq[b] += a;
}

void solve() {
    vector<int>v;
    int cnt = 0;
    memset(seq, 0, sizeof (seq));
    char ts[50], *p;
    p = strtok(str, "+");
    while (p) {
        strcpy(ts, p);
        gao(ts);
        p = strtok(NULL, "+");
    }
    for (int i = 5; i >= 0; --i) {
        if (seq[i] != 0) {
            cnt = i;
            break;
        }
    }
    for (int i = -1000; i <= 1000; ++i) { 
        for (int j = 0; j < cnt; ++j) {
            int rec[10]    = {0};
            qiudao(rec, j);
            if (judge(rec, i)) {
                v.push_back(i);
            } else {
                break;
            }
        }
    }
    //x^4-x^2
    //x^4-7x^3+18x^2-20x+8
    //x^3-13x^2+55x-75
    //x^2+5x^2-6x^2+x^2+2x-20x+30x-10x+8-7
    //x^5-10x^4+39x^3-74x^2+68x-24
    //以上都是能够分解的式子 
    if (v.size() != cnt || seq[cnt] != 1 || cnt == 0) {
        printf("-1\n");
    } else {
        sort(v.begin(), v.end());
        for (int i = v.size()-1; i >= 0; --i) {
            if (v[i] < 0) {
                printf("(x+%d)", -v[i]);
            } else if (v[i] == 0) {
                printf("x");    
            } else {
                printf("(x-%d)", v[i]);    
            }
        }
        puts("");
    }
}

int main() {
    int T, ca = 0;
    scanf("%d", &T);
    while (T--) {
        scanf("%s", str);
        int len = strlen(str);
        for (int i = 0; i < len; ++i) {
            if (str[i] == '-') {
                for (int j = len-1; j >= i; --j) {
                    str[j+1] = str[j];
                }
                str[i] = '+';
                len += 1;
                ++i;
                str[len] = '';
            }
            
        }
        printf("Case #%d: ", ++ca);
        solve();
    }
    return 0;
}


第三题:小小明系列故事——游戏的烦恼

链接:http://acm.hdu.edu.cn/showproblem.php?pid=4518

题解:(转自网上大牛:http://blog.csdn.net/zhuhuangjian/article/details/8711287)

用p[i][j]存放0~i-1 * 0~j-1里的黑点数目。

然后对枚举,

 

 if(p[i+x-1][j+y-1]+p[i-1][j-1]-p[i+x-1][j-1]-p[i-1][j+y-1]==x*y)

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/2090543.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-07-22
下一篇 2022-07-22

发表评论

登录后才能评论

评论列表(0条)

保存