2011暑假集训组队赛1

来源:互联网 发布:erp基础数据的作用 编辑:程序博客网 时间:2024/05/09 05:41
Y1Compression 
2Nimper!Y3JangalestanY4Prime Numbers…Again!
5Word maker!
6Weird Coloring
7Trundling Object
8Remainder Calculator
9Number Convertor

#1 Compression(Water)

理论上是超级水题一道。可就是空格之类的东西折磨了我们三个2,3个小时?诶...

1 #include
2 using namespace DanTeng;
3 cin>>...; 
4 cout<<..<<endl;

值得一提的是,cin,cout比scanf,printf慢。

 

#2 Nimper(DP)

应该算是很难的题吧,有个solution不过说的太泛。

"

Task Given a set of numbers,  you have to remove minimal sum of numbers to obtain a ‘Lose-state’ free set.  A Lose-state is a subset which the binary-exclusive-or of its numbers is equal to zero.
Method Greedy !!!
Solution :
Do the following steps as long as your set contains a Loose-state :
1- Find a loose state.
2- Remove its minimum number from set.

"

 

附上代码,供以后研究:

01 #include 
02 #include 
03 using namespace std;
04 
05 
06 const int maxn=20000;
07 
08 int n;
09 long long A[maxn],S[maxn];
10 
11 int sol()
12 {
13     sort(A,A+n);
14     reverse(A,A+n);
15     for (int i=0;i<n;i++) S[i]=A[i];
16     long long r=0;
17     for (int i=0;i<n;i++)
18         if (S[i]==0
19             r+=A[i];
20         else
21         {
22             long long p=(S[i]^(S[i]-1))&S[i];
23             for (int j=i+1;j<n;j++)
24                 if (S[j]&p)
25                     S[j]^=S[i];
26         }
27     return r;
28         
29 }
30 
31 int main()
32 {
33     int t;
34     cin >> t;
35     for (int test_number=1;test_number<=t;test_number++)
36     {
37         cin >> n;
38         for (int i=0;i<maxn;i++)
39             A[i]=S[i]=0;
40         for (int i=0;i<n;i++)
41             cin >> A[i];
42         cout << sol() << endl;
43     }
44     return 0;
45 }


#3 Jangatestan(DFS)

在图中找相连子部。各种图遍历都可以。边界处理只要在最外圈加通路。及数组从1开始。注意输入后的空格神马的。简直是一种人类思想与灵魂的羁绊。啧啧啧...牛人喜欢把dfs中的枚举存成数组,这样使程序看起来似乎是不那么原始了。

1 int move[8][2]={{0,1},{0,-1},
2                 {1,0},{-1,0},
3                 {1,-1},{1,1},
4                 {-1,1},{-1,-1}
5                 };


#4 Prime Numbers(Water)

找出制定数字可以由几种连续的质数之和表示。连续没有注意到结果坑爹了。数据400程序就跑飞了...其实只要从头穷举,限定几个停止条件就好。打出质数表的方法貌似这个比较优了。只是总是搞不清楚要列到多少。100000的数据为什么大牛们列20000,百思不得解。


#5 Word maker(Maximum matching)
给出一些组合过的字母,一个组合只能用一次。找其匹配串。由此引出二分图最大配匈牙利算法。这些以后慢议。
依旧附上神作:

01 #include 
02 #include 
03 #include 
04 #include 

05 #include 
06 #include 
07 #define MAXN 305
08 using namespace std;
09 
10 int n, m, uN, vN;
11 bool mp[MAXN][26];
12 bool g[MAXN][MAXN];
13 char ip[1005];
14 int xM[MAXN], yM[MAXN];
15 bool chk[MAXN];
16 
17 bool searchPath(int u)
18 {
19     int v;
20     for(v = 0v < vNv++)
21         if(g[u][v] && !chk[v])
22         {
23             chk[v] = true;
24             if(yM[v] == -1 || searchPath(yM[v]))
25             {
26                 yM[v] = uxM[u] = v;
27                 return true;
28             }
29         }
30     return false;
31 }
32 
33 int MaxMatch()
34 {
35     int u, ret = 0;
36     memset(xM, -1, sizeof(xM));
37     memset(yM, -1, sizeof(yM));
38     for(u = 0u < uNu++)
39         if(xM[u] == -1)
40         {
41             memset(chk, false, sizeof(chk));
42             if(searchPath(u)) ret++;
43         }
44     return ret;
45 }
46 
47 int main()
48 {    
49     int t, i, j, k, sum, d;
50 
51     scanf("%d", &t);
52     while(t--)
53     {
54         memset(mp, 0, sizeof(mp));
55         scanf("%d%d", &n, &m);
56         for(i = 0i < n; i++)
57         {
58             scanf("%s", ip);
59             for(j = 0ip[j]; j++)
60                 mp[i][ip[j]-'A'] = 1;
61         }
62         sum = 0;
63         vN = n;
64         for(i = 0i < mi++)
65         {
66             memset(g, 0, sizeof(g));
67             scanf("%s", ip);
68             for(j = 0ip[j]; j++)
69                 for(k = 0k < n; k++)
70                     if(mp[k][ip[j]-'A'])
71                         g[j][k] = 1;
72             uN = strlen(ip);
73             if(MaxMatch() == uN)
74                 sum++;
75         }
76         
77         printf("%d\n", sum);
78     }
79     return 0;
80 }

#6 Wierd Coloring(Gragh,NP)
给你张无向图,往每个边上上色(0,1,2)。要求0色边相邻的为2色,最后求最小上色和。牵扯到了什么完全NPBranch&Bounds之类的。以后细究以后细究...

//blogbus把include 里面<>都吃了,这篇先凑活吧...=.=
原创粉丝点击