| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
共有 42026 人关注过本帖, 47 人收藏
标题:C论坛算法团队 首战 西安电子科技大学OJ
取消只看楼主 加入收藏
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
收藏
得分:0 
呵呵,我以为你要这个映射关系的原理呢。你曹哥还是那么话少

重剑无锋,大巧不工
2012-12-09 16:13
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
收藏
得分:0 
这个甚至可以说必须用位运算。
程序代码:
#include<stdio.h>
int main()
{
    int a, x, y;
    scanf("%x,%d,%d", &a, &x, &y);
    printf("%x", a & ~((1 << x) | (1 << y - 2)) | (3 << y - 1));
    return 0;
}

 

重剑无锋,大巧不工
2012-12-11 14:49
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
收藏
得分:0 
位运算是计算机最基础的运算方式,其它运算都是基于此的。一定要好好掌握。

重剑无锋,大巧不工
2012-12-11 15:26
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
收藏
得分:0 
专门的书还真不知道,一般语言教程的前几章都会讲的。离散数学和数电也都有。

这段代码,不是我不想讲,是我真不知道该怎么讲才好。

这样吧,你先理解一下下面的例子

清零
f = 1 << x; //形成第x位为1,其它位都是0的位串

f = ~f; //对f取反,作用是反转位串中的0和1

a = a & f; //将a中第x位清0

置1
f = 1 << x;
a = a | f; //将a中第x位置1


重剑无锋,大巧不工
2012-12-11 15:52
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
收藏
得分:0 
呵呵,小曹果然不负众望。

我知道的二分图最大匹配算法我也只知道匈牙利算法而已。

与你的不同之处在于你用的是DFS,而我用的是BFS。回头我要对比一下你我程序的差别。

展示一下我的WA代码吧。关于机枪能自毁这事当我看到它的攻击范围是从0开始时已经意识到了。

最近没有玩ACM的心情,休息一下。呵呵,就辛苦两位了。

程序代码:
#include<stdio.h>
#define M    100
int cal(int map[][M], int n)
{
    int x[M] = {}, lx[M], mx[M];
    int y[M] = {}, ly[M], my[M];
    int c = 0, lxn, lyn, i, j, k, t;
   
    for(c = i = 0; i < n; i++)
    {
        if(x[i]) continue;
        for(j = 0; j < n; j++) mx[j] = my[j] = 0;
        mx[i] = 1;
        lx[0] = i;
        lxn = 1;
        lyn = 0;
        for(k = j = 0; j < lxn; j++)
        {
            for(t = 0; t < n; t++)
            {
                if(!map[lx[j]][t] || my[t]) continue;
                if(y[t]){ my[t] = 1; ly[lyn++] = t;}
                else{ x[i] = 1; y[t] = 1; c++; break;}
            }
            if(t != n) break;
            for(; k < lyn; k++)
            for(t = 0; t < n; t++)
            if(x[t] && map[t][ly[k]] && !mx[t])
            {
                lx[lxn++] = t;
                mx[t] = 1;
            }
        }
    }
    return c;
}
int main()
{
    int map[M][M], x[M], y[M], s[M], e[M];
    int t, n, i, j, d;
    for(scanf("%d", &t); t--; printf("%d\n", cal(map, n)))
    {
        for(scanf("%d", &n), i = 0; i < n; s[i] *= s[i], e[i] *= e[i], i++)
            scanf("%d%d%d%d", &x[i], &y[i], &s[i], &e[i]);
        for(i = 0; i < n; i++)
        for(j = 0; j < n; j++)
            map[i][j] = (d = (d = x[i] - x[j]) * d + (d = y[i] - y[j]) * d) >= s[i] && d <= e[i];
    }
    return 0;
}

重剑无锋,大巧不工
2012-12-12 20:01
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
收藏
得分:0 
呵呵,你知道我和小曹都不是计算机专业的吧。我是电气工程专业的,小曹好像是学医的。

我也很少给别人学习方法方面的建议,毕竟个人情况不同。

小曹具体怎么学我不知道,我从初中开始接触编程,完全是兴趣,想学什么就找什么资料,仅此而已。

重剑无锋,大巧不工
2012-12-13 22:41
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
收藏
得分:0 
好像最近没见有新题被解答。看来小曹和小戴也累了呵呵,没关系休息一下玩玩别的换换脑子也好。

最近除了工作我也在忙点别的事情,希望各位谅解。

重剑无锋,大巧不工
2012-12-21 11:34
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
收藏
得分:0 
Problem 1040 - Banner
小戴的建议也不错,不过先把这题发上来。
Problem 1040 - Banner

Time Limit: 1000MS   Memory Limit: 65536KB   Difficulty:
Total Submit: 4  Accepted: 4  Special Judge: No


Description


    Bessie is returning from a long trip abroad, and Farmer John wantsto erect a nice "Welcome Home" banner in her pasture for her arrival.The banner will hang between two poles on a wire whose length isin the range L1..L2 (1 <= L1 <= L2; L1 <= L2 <= 1,500).

    The pasture's size is W x H (1 <= W <= 1,000; 1 <= H <= 1,000), and Farmer John has installed a post at every point with integer coordinates. Of these (W + 1) * (H + 1) points, Farmer John must pick just two that will hold either end of the wire from which he will hang the banner.

    FJ wants no interference with his banner as it hangs and requires that no post be directly under the tight wire he stretches between the two chosen posts.

    Farmer John needs your help to figure out how many possible ways he can hang the banner. He knows the number is large and that a 32-bit integer might not be sufficient to compute the answer.

   Consider the example pasture below, with W = 2 and H = 1:

       * * *

       * * *

    The banner size is in the range 2..3. This pasture contains (2+1)* (1+1) = 6 points and has (6 take 2) = (6*5)/(2*1) = 15 different potential pairs of points between which the banner-holding wire might stretch:

   (0,0)-(0,1)   (0,0)-(2,1)   (0,1)-(2,1)   (1,1)-(2,0)

   (0,0)-(1,0)   (0,1)-(1,0)   (1,0)-(1,1)   (1,1)-(2,1)

   (0,0)-(1,1)   (0,1)-(1,1)   (1,0)-(2,0)   (2,0)-(2,1)

   (0,0)-(2,0)   (0,1)-(2,0)   (1,0)-(2,1)

    Of these pairs, only four have a length in the range 2..3:

                     Len                       Len

        (0,0)-(2,0) 2.00          (0,1)-(2,0) 2.24

        (0,0)-(2,1) 2.24          (0,1)-(2,1) 2.00

    Of these four, the pairs (0,0)-(2,0) and (0,1)-(2,1) both have a post directly on the line between the endpoints, and thus are unsuitable.

    So, just two pairs of points out of 15 are acceptable candidates for hanging the banner wire.

Input

Line 1: Four space-separated integers: W, H, L1, and L2


Output

Line 1: A single integer denoting the number of possible banners


Sample Input

2 1 2 3


Sample Output

2


Hint


Source

USACO NOV10 SILVER
分析
好久不见奶牛贝斯和农夫约翰了,呵呵这可是USACO里很出名的故事人物。
 
在 W x H 的农场里找两个点,使得它们的距离介于L1与L2之间,而且它们的连线上不能有其它点。问这样的点对有多少。
 
如果把这两个点当做一个矩形的对角线,那问题就转化成在农场里可以划出多少个矩形。
 
而要求这个矩形的对角线上没有其它点,既是要求矩形的两边是互质的。
程序代码:
#include<stdio.h>
long long cal(int W, int H, int L1, int L2)
{
    long long c;
    int i, j, di, d, t, t1, t2;
    c = L1 == 1 ? W * H * 2 + W + H : 0;
    L1 *= L1;
    L2 *= L2;
    for(di = i = 1; i <= W; di += (++i << 1) - 1)
    for(d = di + (j = 1); j <= H && d <= L2; d += (++j << 1) - 1)
    {
        if(d < L1) continue;
        for(t1 = i, t2 = j; t = t1 % t2; t1 = t2, t2 = t);
        if(t2 == 1) c += (W - i + 1) * (H - j + 1) << 1;
    }
    return c;
}

int main()
{
    int W, H, L1, L2;
    scanf("%d%d%d%d", &W, &H, &L1, &L2);
    printf("%lld\n", cal(W, H, L1, L2));
    return 0;
}


[ 本帖最后由 beyondyf 于 2012-12-22 20:45 编辑 ]

重剑无锋,大巧不工
2012-12-22 20:44
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
收藏
得分:0 
顺便总结一下到现在已经完成的题目

1001 1002 1003 1004 1005 1006 1007 1008 1009 1010

1011 1012 1013 1014 1015 1016 1017 1018 1019 1020

1021 1022 1023 1024 1025 1026 1027 1028 1029 1030

1031 1032 1033 1034 1035 1036 1037 1038 1039 1040

1043 1049

1053 1054 1055

1061 1069

1076

1103 1109

1121 1130

1178

1201 1206 1207 1209

重剑无锋,大巧不工
2012-12-22 20:48
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
收藏
得分:0 
Problem 1202 - Meepo's problem II
Problem 1202 - Meepo's problem II

Time Limit: 1000MS   Memory Limit: 131072KB   Difficulty:
Total Submit: 2  Accepted: 1  Special Judge: No


Description


 Meepo the Geomancer is a mischievous spirit of the earth who enjoys burying his enemies alive in mountains of rock spikes.We all know that Meepo can summons some duplicate of himself,the clones are independent to each other and have the same abilities as Meepo.

When the Kth Meepo clone be summoned, this clone gain F(K,D) extra damage.

  Here F(K,D) means the Kth small prime factor of D,where D is the primary Meepo's damage.

  For example if primary Meepo's damage is 12, F(1,12) = 2.

  And if K is bigger than the numbers of D's prim factor, F(K,D) = D.

  Now if Meepo's damge range is [Li , Ri] , he want to know his Kth clone's

damage range.

Input

 First line a number n (n<=100000),means Meepo's query.
  Next n line, 3 positive integer a line: Li,Ri,K ,means Meepo's damage range is [Li,Ri],
and he wants to know his Kth clone's damage range.
  All Li,Ri,and K are no more than 500000 and Li<=Ri.

Output

 For every query, print two integer [L,R],means Meepo's clone's damage range.

Sample Input

3
17 47 3
11 36 7
3 16 1

Sample Output

34 94
22 72
6 26

Hint

Source

eggeek
分析
我魔兽玩的很烂。在同事的诱惑下玩了几次,不过发现自己真没这方面的天赋。相比自己去玩我更愿意看他们玩(更准确点是听),我这帮同事打魔兽时太有意思了,跟说相声似的。

书归正传,这个题目涉及两方面的计算,一是因式分解,另一个是最大最小值的检索。

由于数据量很大,所以直接的检索是行不通的。

直接检索的时间复杂度为O(n*m)。n是测试数据组数,m是检索范围,两个参数的上限都很大,所以轻松超时。

对此可以使用线段树来提高检索效率,将时间复杂度降到O(n * log(m))。

至于因式分解,可以改造一下素数筛来完成。
程序代码:
#include<stdio.h>

#define MAX_RANGE    500000
#define MAX_FN        7

struct
{
    int L, R;
    int max[MAX_FN];
    int min[MAX_FN];
    int il, ir;
} ST[MAX_RANGE * 2];

int FL, FR, K;

void build_tree(int L, int R, int root)
{
    static int ip = MAX_RANGE + 1;
    int i;
   
    ST[root].L = L;
    ST[root].R = R;
    i = (L + R) >> 1;
    if(i == L) ST[root].il = L; else build_tree(L, i, ST[root].il = ip++);
    if(i + 1 == R) ST[root].ir = R; else build_tree(i + 1, R, ST[root].ir = ip++);

    for(i = 0; i < MAX_FN; i++)
    {
        ST[root].max[i] = ST[ST[root].il].max[i] > ST[ST[root].ir].max[i] ? ST[ST[root].il].max[i] : ST[ST[root].ir].max[i];
        ST[root].min[i] = ST[ST[root].il].min[i] < ST[ST[root].ir].min[i] ? ST[ST[root].il].min[i] : ST[ST[root].ir].min[i];
    }
}

void init()
{
    int  i, j, t;

    ST[1].L = ST[1].R = 1;
    for(i = 0; i < MAX_FN; i++) ST[1].max[i] = ST[1].min[i] = 2;

    for(i = 2; i <= MAX_RANGE; i++)
    {
        ST[i].L = ST[i].R = i;
        if(!ST[i].il)
        for(j = i + i; j <= MAX_RANGE; ST[j].il++, j += i) ST[j].max[ST[j].il] = ST[j].min[ST[j].il] = i + j;
        for(t = i + i, j = ST[i].il; j < MAX_FN; j++) ST[i].max[j] = ST[i].min[j] = t;
    }
    build_tree(1, MAX_RANGE, 0);
}

void search(int L, int R, int root)
{
    if(L > ST[root].R || R < ST[root].L) return;
    if(L <= ST[root].L && R >= ST[root].R)
    {
        if(FL > ST[root].min[K]) FL = ST[root].min[K];
        if(FR < ST[root].max[K]) FR = ST[root].max[K];
        return;
    }
    if(L < ST[root].L) L = ST[root].L;
    if(R > ST[root].R) R = ST[root].R;
    search(L, R, ST[root].il);
    search(L, R, ST[root].ir);
}

void output(int L, int R)
{
    FL = MAX_RANGE * 2;
    FR = 1;
    K = K > MAX_FN ? MAX_FN - 1 : K - 1;
    search(L, R, 0);
    printf("%d %d\n", FL, FR);
}

int main()
{
    int n, Li, Ri;

    init();
    for(scanf("%d", &n); n--; output(Li, Ri))
        scanf("%d%d%d", &Li, &Ri, &K);
    return 0;
}

重剑无锋,大巧不工
2012-12-24 21:48
快速回复:C论坛算法团队 首战 西安电子科技大学OJ
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021111 second(s), 10 queries.
Copyright©2004-2025, BC-CN.NET, All Rights Reserved