码迷,mamicode.com
首页 > 其他好文 > 详细

2017 icpc 南宁网络赛

时间:2017-09-24 22:16:44      阅读:491      评论:0      收藏:0      [点我收藏+]

标签:size   image   spec   void   rate   leaves   ret   dig   oid   

2000年台湾大专题。。。英语阅读输入输出专场。。我只能说很强势。。

M. Frequent Subsets Problem

The frequent subset problem is defined as follows. Suppose UU={1, 2,\ldots…,N} is the universe, and S_{1}S?1??, S_{2}S?2??,\ldots…,S_{M}S?M?? are MM sets over UU. Given a positive constant \alphaα, 0<\alpha \leq 10<α1, a subset BB (B \neq 0B0) is α-frequent if it is contained in at least \alpha MαM sets of S_{1}S?1??, S_{2}S?2??,\ldots…,S_{M}S?M??, i.e. \left | \left \{ i:B\subseteq S_{i} \right \} \right | \geq \alpha M{i:B?S?i??}αM. The frequent subset problem is to find all the subsets that are α-frequent. For example, let U=\{1, 2,3,4,5\}U={1,2,3,4,5}, M=3M=3, \alpha =0.5α=0.5, and S_{1}=\{1, 5\}S?1??={1,5}, S_{2}=\{1,2,5\}S?2??={1,2,5}, S_{3}=\{1,3,4\}S?3??={1,3,4}. Then there are 33 α-frequent subsets of UU, which are \{1\}{1},\{5\}{5} and \{1,5\}{1,5}.

Input Format

The first line contains two numbers NN and \alphaα, where NN is a positive integers, and \alphaα is a floating-point number between 0 and 1. Each of the subsequent lines contains a set which consists of a sequence of positive integers separated by blanks, i.e., line i + 1i+1 contains S_{i}S?i??, 1 \le i \le M1iM . Your program should be able to handle NN up to 2020 and MM up to 5050.

Output Format

The number of \alphaα-frequent subsets.

样例输入

15 0.4
1 8 14 4 13 2
3 7 11 6
10 8 4 2
9 3 12 7 15 2
8 3 2 4 5

样例输出

11


输入坑。。还有题面英语阅读就顺便说下。。
然后把M个集合变成二进制,相应位代表该数字是否存在。暴力枚举0~(1<<n)-1,每个数字代表一个集合,然后检查1~m里面有几个枚举集合是他的子集。把两个数字或一下如果是子集的话数字不变,不是则改变。
技术分享
 1 #include<bits/stdc++.h>
 2 #define clr(x) memset(x,0,sizeof(x))
 3 #define clr_1(x) memset(x,-1,sizeof(x))
 4 #define LL long long
 5 #define mod 1000000007
 6 using namespace std;
 7 const int N=1e2+10;
 8 int vis[N][N];
 9 int num[N];
10 int n,m,T,k,ct,len,p,gg,tt;
11 double aef;
12 string s;
13 int main()
14 {
15     scanf("%d%lf",&n,&aef);
16     m=0;
17     clr(vis);
18     clr(num);
19     getline(cin,s);
20     while(getline(cin,s))
21     {
22         m++;
23         k=0;
24         for(int i=0;i<s.size();i++)
25             if(s[i]>9 || s[i]<0)
26             {
27                 vis[m][k]++;
28                 k=0;
29             }
30             else
31             {
32                 k*=10;
33                 k+=s[i]-0;
34             }
35         vis[m][k]++;
36         for(int i=1;i<=n;i++)
37         {
38             if(vis[m][i])
39                 num[m]|=(1<<(i-1));
40         }
41     }
42     tt=m;
43     if(abs(m*aef-(int)(m*aef))<=1e-6)
44         tt=(int)(m*aef+0.5);
45     else
46         tt=m*aef+1;
47     p=0;
48     len=(1<<n);
49     for(int i=1;i<len;i++)
50     {
51         ct=0;
52         for(int j=1;j<=m;j++)
53             if((i|num[j])==num[j])
54                 ct++;
55         if(ct>=tt)
56             p++;
57     }
58     printf("%d\n",p);
59     return 0;
60 }
View Code

 

L, The Heaviest Non-decreasing Subsequence Problem

Let SS be a sequence of integers s_{1}s?1??, s_{2}s?2??, ......, s_{n}s?n??Each integer is is associated with a weight by the following rules:

(1) If is is negative, then its weight is 00.

(2) If is is greater than or equal to 1000010000, then its weight is 55. Furthermore, the real integer value of s_{i}s?i?? is s_{i}-10000s?i???10000 . For example, if s_{i}s?i??is 1010110101, then is is reset to 101101 and its weight is 55.

(3) Otherwise, its weight is 11.

A non-decreasing subsequence of SS is a subsequence s_{i1}s?i1??, s_{i2}s?i2??, ......, s_{ik}s?ik??, with i_{1}<i_{2}\ ...\ <i_{k}i?1??<i?2?? ... <i?k??, such that, for all 1 \leq j<k1j<k, we have s_{ij}<s_{ij+1}s?ij??<s?ij+1??.

A heaviest non-decreasing subsequence of SSis a non-decreasing subsequence with the maximum sum of weights.

Write a program that reads a sequence of integers, and outputs the weight of its

heaviest non-decreasing subsequence. For example, given the following sequence:

808757737939737737101011010979-1?-1?11411-1?1101131011118118

The heaviest non-decreasing subsequence of the sequence is <73, 73, 73, 101, 113, 118><73,73,73,101,113,118> with the total weight being 1+1+1+5+5+1 = 141+1+1+5+5+1=14. Therefore, your program should output 1414 in this example.

We guarantee that the length of the sequence does not exceed 2*10^{5}2?10?5??

Input Format

A list of integers separated by blanks:s_{1}s?1??, s_{2}s?2??,......,s_{n}s?n??

Output Format

A positive integer that is the weight of the heaviest non-decreasing subsequence.

样例输入

80 75 73 93 73 73 10101 97 -1 -1 114 -1 10113 118

样例输出

14

最长不下降子序列问题。用树状数组的标准nlogn做法。
技术分享
 1 #include<bits/stdc++.h>
 2 #define clr(x) memset(x,0,sizeof(x))
 3 #define clr_1(x) memset(x,-1,sizeof(x))
 4 #define LL long long
 5 #define mod 1000000007
 6 using namespace std;
 7 const int N=1e4+10;
 8 const int NN=1e4+1;
 9 const int M=2e5+10;
10 int bit[N];
11 int val[M],wei[M],ans,maxn;
12 int sum(int i)
13 {
14     int s=0;
15     while(i>0)
16     {
17         s=max(s,bit[i]);
18         i-=i&-i;
19     }
20     return s;
21 }
22 void add(int i,int x)
23 {
24     while(i<=NN)
25     {
26         bit[i]=max(bit[i],x);
27         i+=i&-i;
28     }
29     return ;
30 }
31 int ct,n,m,k,T;
32 int main()
33 {
34     n=1;
35     while(scanf("%d",&val[n])!=EOF)
36     {
37         if(val[n]>=0)
38             n++;
39     }
40     n--;
41     for(int i=1;i<=n;i++)
42     {
43         if(val[i]>=10000)
44         {
45             val[i]-=10000;
46             wei[i]=5;
47         }
48         else
49             wei[i]=1;
50     }
51     clr(bit);
52     maxn=0;
53     for(int i=1;i<=n;i++)
54     {
55         ans=sum(val[i])+wei[i];
56         maxn=max(maxn,ans);
57         add(val[i],ans);
58     }
59     printf("%d\n",maxn);
60     return 0;
61 }
View Code

 

 J. Minimum Distance in a Star Graph

In this problem, we will define a graph called star graph, and the question is to find the minimum distance between two given nodes in the star graph.

Given an integer nn, an n-dimensionaln?dimensionalstar graph, also referred to as S_{n}S?n??, is an undirected graph consisting of n!n! nodes (or vertices) and ((n-1)\ *\ n!)/2((n?1) ? n!)/2 edges. Each node is uniquely assigned a label x_{1}\ x_{2}\ ...\ x_{n}x?1?? x?2?? ... x?n??which is any permutation of the n digits {1, 2, 3, ..., n}1,2,3,...,n. For instance, an S_{4}S?4?? has the following 24 nodes {1234, 1243, 1324, 1342, 1423, 1432, 2134, 2143, 2314, 2341, 2413, 2431, 3124, 3142, 3214, 3241, 3412, 3421, 4123, 4132, 4213, 4231, 4312, 4321}1234,1243,1324,1342,1423,1432,2134,2143,2314,2341,2413,2431,3124,3142,3214,3241,3412,3421,4123,4132,4213,4231,4312,4321. For each node with label x_{1}\ x_{2} x_{3}\ x_{4}\ ...\ x_{n}x?1?? x?2??x?3?? x?4?? ... x?n??, it has n-1n?1 edges connecting to nodes x_{2}\ x_{1}\ x_{3}\ x_{4}\ ...\ x_{n}x?2?? x?1?? x?3?? x?4?? ... x?n??, x_{3}\ x_{2}\ x_{1}\ x_{4}\ ...\ x_{n}x?3?? x?2?? x?1?? x?4?? ... x?n??, x_{4}\ x_{2}\ x_{3}\ x_{1}\ ...\ x_{n}x?4?? x?2?? xx_{n}\ x_{2}\ x_{3}\ x_{4}\ ...\ x_{1}n-1d-thx_{1}\ x_{2}\ x_{3}\ x_{4}\ ...\ x_{n}d = 2, ..., nS_{4}12343213432144231S_{4}abcd?3?? x?1?? ... x?n??, ..., and x?n?? x?2?? x?3?? x?4?? ... x?1??. That is, the n?1adjacent nodes are obtained by swapping the first symbol and the d?th symbol of x?1?? x?2?? x?3?? x?4?? ... x?n??, for d=2,...,n. For instance, in S?4??, node 1234 has 3 edges connecting to nodes 2134, 3214, and 4231. The following figure shows how S?4?? looks (note that the symbols a, b, c, and d are not nodes; we only use them to show the connectivity between nodes; this is for the clarity of the figure).

技术分享

In this problem, you are given the following inputs:

  • nn: the dimension of the star graph. We assume that nn ranges from 44 to 99.
  • Two nodes x_{1}x?1?? x_{2}x?2?? x_{3}x?3?? ... x_{n}x?n?? and y_{1}y?1?? y_{2}y?2?? y_{3}\ ...\ y_{n}y?3?? ... y?n?? in S_{n}S?n??.

You have to calculate the distance between these two nodes (which is an integer).

Input Format

nn (dimension of the star graph)

A list of 55 pairs of nodes.

Output Format

A list of 55 values, each representing the distance of a pair of nodes.

样例输入

4
1234 4231
1234 3124
2341 1324
3214 4213
3214 2143

样例输出

1
2
2
1
3

题意就是把第一串变成第二串要几步,变换规则是只能把第一个位置和任意一个位置交换。
跟普通的通过交换位置把一个混乱序列变为一个指定序列相似,每个位置的数直接交换到他该到的位置就行。
但有k个交换循环就要加(k-1)*2的次数,因为除了第一个数字在的循环,其他循环节都得某个位置交换到1以后再交换,比正常直接交换多2。
技术分享
 1 #include<bits/stdc++.h>
 2 #define clr(x) memset(x,0,sizeof(x))
 3 #define clr_1(x) memset(x,-1,sizeof(x))
 4 #define LL long long
 5 #define mod 1000000007
 6 using namespace std;
 7 const int N=1e2+10;
 8 const int NN=1e4+1;
 9 const int M=2e5+10;
10 int n;
11 string s1,s2;
12 int num[N],ct,flag=0;;
13 int main()
14 {
15     scanf("%d",&n);
16     for(int kase=1;kase<=5;kase++)
17     {
18         cin>>s1;
19         cin>>s2;
20         for(int i=0;i<s2.size();i++)
21             num[s2[i]-0]=i;
22         ct=0;
23         flag=0;
24         for(int i=0;i<s1.size();i++)
25         {
26             if(s1[i]!=s2[i] && i>0)
27                 flag++;
28             while(s1[i]!=s2[i])
29             {
30                 swap(s1[i],s1[num[s1[i]-0]]);
31                 ct++;
32             }
33         }
34         if(flag)
35             ct+=2*flag;
36         printf("%d\n",ct);
37     }
38     return 0;
39 }
View Code

 

 H. A Cache Simulator

Cache memories have been used widely in current microprocessor systems. In this problem, you are asked to write a program for a cache simulator. The cache has the following metrics:

1. The cache size is 1 KB (K-byte).

2. The cache uses the direct mapped approach.

3. The cache line size is 16 bytes.

4. The cacheable memory size is 256MB.

Your program will report a hit or miss when an address is given to the cache simulator. This is often called trace simulation. Initially, all of the cache lines are in the invalid state. When a memory line is first brought into the cache, the allocated cache entry transits into the valid state. Assume that a miss causes the filling of a whole cache line.

Input Format

Up to 100100 lines of address can be given in the file. Each line consists of an address given to the simulator. The address is given in hexadecimal form. We assume that each address references only one byte of data. The input file ends at the line with the word ENDEND.

Output Format

Report either HitHit or MissMiss for each of the given addresses. The last line reports cache hit ratio in percentage, that is, the number of hits divided by the number of total addresses given.

样例输入

AAAA000
00010B2
00010BA
END

样例输出

Miss
Miss
Hit
Hit ratio = 33.33%



已经忘了计算机组成原理,队友写的,队友解释一番我才懂cache内存怎么分配。。
学过计组,英语好的话你就懂了。。。
技术分享
 1 //zq‘s code
 2 #include <bits/stdc++.h>
 3 using namespace std;
 4 typedef long long ll;
 5 const int N = 2000;
 6 const int cacheSize = 16;
 7 const int lineSize = 64;
 8 
 9 int cnt[N];
10 string s;
11 int a, b;
12 
13 void slove() {
14     memset(cnt, -1, sizeof(cnt));
15     a = 0;
16     b = 0;
17     while(cin >> s){
18         if(s == "END") break;
19         b ++;
20         int ans = 0;
21         for(int i = 0; i < s.size(); ++ i) {
22             int tmp;
23             if(s[i] >= A) {
24                 tmp = s[i] - A + 10;
25             }
26             else {
27                 tmp = s[i] - 0;
28             }
29             ans = ans * 16 + tmp;
30         }
31         ans = ans / cacheSize;
32         
33         if(cnt[ans%lineSize] == ans) {
34             puts("Hit");
35             ++ a;
36         }
37         else {
38             puts("Miss");
39         }
40         cnt[ans%lineSize] = ans;
41     }
42     printf("Hit ratio = %.2lf", 100.0 * a / b);
43     puts("%");
44 }
45 
46 int main() {
47     slove();
48     return 0;
49 }
View Code

G.Finding the Radius for an Inserted Circle

Three circles C_{a}C?a??, C_{b}C?b??, and C_{c}C?c??, all with radius RRand tangent to each other, are located in two-dimensional space as shown in Figure 11. A smaller circle C_{1}C?1?? with radius R_{1}R?1?? (R_{1}<RR?1??<R) is then inserted into the blank area bounded by C_{a}C?a??, C_{b}C?b??, and C_{c}C?c?? so that C_{1}C?1?? is tangent to the three outer circles, C_{a}C?a??, C_{b}C?b??, and C_{c}C?c??. Now, we keep inserting a number of smaller and smaller circles C_{k}\ (2 \leq k \leq N)C?k?? (2kN) with the corresponding radius R_{k}R?k?? into the blank area bounded by C_{a}C?a??, C_{c}C?c?? and C_{k-1}C?k?1?? (2 \leq k \leq N)(2kN), so that every time when the insertion occurs, the inserted circle C_{k}C?k?? is always tangent to the three outer circles C_{a}C?a??, C_{c}C?c?? and C_{k-1}C?k?1??, as shown in Figure 11

技术分享

Figure 1.

(Left) Inserting a smaller circle C_{1}C?1?? into a blank area bounded by the circle C_{a}C?a??, C_{b}C?b?? and C_{c}C?c??.

(Right) An enlarged view of inserting a smaller and smaller circle C_{k}C?k?? into a blank area bounded by C_{a}C?a??, C_{c}C?c?? and C_{k-1}C?k?1?? (2 \leq k \leq N2kN), so that the inserted circle C_{k}C?k?? is always tangent to the three outer circles, C_{a}C?a??, C_{c}C?c??, and C_{k-1}C?k?1??.

Now, given the parameters RR and kk, please write a program to calculate the value of R_{k}R?k??, i.e., the radius of the k-thk?th inserted circle. Please note that since the value of R_kR?k?? may not be an integer, you only need to report theinteger part of R_{k}R?k??. For example, if you find that R_{k}R?k?? = 1259.89981259.8998 for some kk, then the answer you should report is 12591259.

Another example, if R_{k}R?k?? = 39.102939.1029 for some kk, then the answer you should report is 3939.

Assume that the total number of the inserted circles is no more than 1010, i.e., N \leq 10N10. Furthermore, you may assume \pi = 3.14159π=3.14159. The range of each parameter is as below:

1 \leq k \leq N1kN, and 10^{4} \leq R \leq 10^{7}10?4??R10?7??.

Input Format

Contains l + 3l+3 lines.

Line 11: ll ----------------- the number of test cases, ll is an integer.

Line 22: RR ---------------- RR is a an integer followed by a decimal point,then followed by a digit.

Line 33: kk ---------------- test case #11, kk is an integer.

\ldots

Line i+2i+2: kk ----------------- test case # ii.

\ldots

Line l +2l+2: kk ------------ test case #ll.

Line l + 3l+3: -1?1 ---------- a constant -1?1representing the end of the input file.

Output Format

Contains ll lines.

Line 11: kR_{k}R?k?? ----------------output for the value ofkk and R_{k}R?k?? at the test case #11, each of which should be separated by a blank.

\ldots

Line ii: kR_{k}R?k?? ----------------output for kk and the value of R_{k}R?k?? at the test case # ii, each of which should be separated by a blank.

Line ll: kR_{k}R?k?? ----------------output for kk and the value ofR_{k}R?k?? at the test case # ll, each of which should be separated by a blank.

样例输入

1
152973.6
1
-1

样例输出

1 23665

题意就是求三个相切的圆(Ca,Cb,Cc的半径为R)内的缝隙内的与三个圆相切的圆C1的半径作为r1,然后选择Ca,Cb和r1以同样方法做出C2和半径r2,依此做出r3..r4...rn。
又是很长很难理解的题面和奇怪输入坑,倒是取整没坑。这题就是高中数学题。r1是求一个求等边三角形的重心(三角形的三个顶点是三个圆圆心),列个方程然后就能求出r1了。接下来这个圆心和ca,cb的圆心又能求出r2。然后r3,r4。。。解个三角形方程求出递推式就能求出所有的ri。
技术分享
 1 #include<bits/stdc++.h>
 2 #define clr(x) memset(x,0,sizeof(x))
 3 #define clr_1(x) memset(x,-1,sizeof(x))
 4 #define LL long long
 5 #define mod 1000000007
 6 using namespace std;
 7 const int N=1e2+10;
 8 double rk[N];
 9 double r,t,lefted,R;
10 int n,T,k,q;
11 int main()
12 {
13     while(scanf("%d",&n)!=EOF && n!=-1)
14     {
15         scanf("%lf",&R);
16         rk[11]=R;
17         lefted=sqrt(3)*R;
18         for(int i=10;i>=1;i--)
19         {
20             t=lefted-rk[i+1];
21             rk[i]=t*t/2/(t+R);
22             lefted=lefted-rk[i+1]-rk[i];
23         }
24         for(int i=1;i<=5;i++)
25             swap(rk[i],rk[10-i+1]);
26         for(int i=1;i<=n;i++)
27         {
28             scanf("%d",&q);
29             printf("%d %d\n",q,int(rk[q]+(1e-9)));
30         }
31     }
32     return 0;
33 }
View Code

 

F.Overlapping Rectangles

There are nn rectangles on the plane. The problem is to find the area of the union of these rectangles. Note that these rectangles might overlap with each other, and the overlapped areas of these rectangles shall not be counted more than once. For example, given a rectangle AA with the bottom left corner located at (0, 0)(0,0) and the top right corner at (2, 2)(2,2), and the other rectangle BB with the bottom left corner located at (1,1)(1,1) and the top right corner at (3,3)(3,3), it follows that the area of the union of AA and BB should be 77, instead of 88.

Although the problem looks simple at the first glance, it might take a while to figure out how to do it correctly. Note that the shape of the union can be very complicated, and the intersected areas can be overlapped by more than two rectangles.

Note:

(1) The coordinates of these rectangles are given in integers. So you do not have to worry about the floating point round-off errors. However, these integers can be as large as 1,000,0001,000,000.

(2) To make the problem easier, you do not have to worry about the sum of the areas exceeding the long integer precision. That is, you can assume that the total area does not result in integer overflow.

Input Format

Several sets of rectangles configurations. The inputs are a list of integers. Within each set, the first integer (in a single line) represents the number of rectangles, n, which can be as large as 10001000. After n, there will be n lines representing the n rectangles; each line contains four integers <a, b, c, d><a,b,c,d> , which means that the bottom left corner of the rectangle is located at (a, b)(a,b), and the top right corner of the rectangle is located at (c, d)(c,d). Note that integers aa, bb, cc, dd can be as large as 1,000,0001,000,000.

These configurations of rectangles occur repetitively in the input as the pattern described above. An integer n = 0n=0 (zero) signifies the end of input.

Output Format

For each set of the rectangles configurations appeared in the input, calculate the total area of the union of the rectangles. Again, these rectangles might overlap each other, and the intersecting areas of these rectangles can only be counted once. Output a single star ‘*‘ to signify the end of outputs.

样例输入

2
0 0 2 2
1 1 3 3
3
0 0 1 1
2 2 3 3
4 4 5 5
0

样例输出

7
3
*

扫描线求面积并题。放个队友代码~
技术分享
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 #include <cstring>
 5 
 6 using namespace std;
 7 
 8 typedef long long ll;
 9 const int inf = 0x3f3f3f3f;
10 const int MAXN = 10010;
11 int n;
12 int t[MAXN];
13 int HASH[MAXN],sum[MAXN];
14 struct data{
15     int x1,x2,y;int f;
16 }a[MAXN];
17 inline bool operator<(data a,data b){
18     return a.y<b.y;
19 }
20 int findup(int x)
21 {
22     int l=1,r=2*n;
23     while(l<=r)
24     {
25         int mid=(l+r)>>1;
26         if(HASH[mid]<x)l=mid+1;
27         else if(HASH[mid]==x)return mid;
28         else r=mid-1;
29     }
30 }
31 void PUSHUP(int k,int l,int r)
32 {
33     if(t[k])
34         sum[k]=HASH[r+1]-HASH[l];
35     else if(l==r)
36         sum[k]=0;
37     else 
38         sum[k]=sum[k<<1]+sum[k<<1|1];
39 }
40 void update(int k,int l,int r,int x,int y,int f)
41 {
42     if(x==l&&y==r)
43     {
44         t[k]+=f;PUSHUP(k,l,r);
45         return;
46     }
47     int mid=(l+r)>>1;
48     if(y<=mid)
49         update(k<<1,l,mid,x,y,f);
50     else if(x>mid)
51         update(k<<1|1,mid+1,r,x,y,f);
52     else
53     {
54         update(k<<1,l,mid,x,mid,f);
55         update(k<<1|1,mid+1,r,mid+1,y,f);
56     }
57     PUSHUP(k,l,r);
58 }
59 void solve(){
60     memset(t,0,sizeof(t));
61     memset(sum,0,sizeof(sum));
62     int x1,y1,x2,y2;
63     for(int i=1;i<=n;i++){
64         scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
65         a[2*i-1].x1=a[2*i].x1=x1;
66         a[2*i-1].x2=a[2*i].x2=x2;
67         a[2*i-1].y=y1;a[2*i].y=y2;
68         a[2*i-1].f=1;a[2*i].f=-1;
69         HASH[2*i-1]=x1;HASH[2*i]=x2;
70     }
71     sort(HASH+1,HASH+2*n+1);
72     sort(a+1,a+2*n+1);
73     int ans=0;
74     for(int i=1;i<=2*n;i++){
75         int l=findup(a[i].x1),r=findup(a[i].x2)-1;
76         if(l<=r)update(1,1,2*n,l,r,a[i].f);
77         ans+=sum[1]*(a[i+1].y-a[i].y);
78     }
79     printf("%d\n",ans);
80 }
81 int main()
82 {
83     while(scanf("%d",&n))
84     {
85         if(n==0){
86             printf("*\n");
87             break;
88         }
89         solve();
90     }
91     return 0;
92 }
View Code

 

 C. Auction Bidding

Company ABC is holding an antique auction. In the auction, there are NN, 1 \leq N \leq 10001N1000, lots. We number the lots from 11 to NN. There are MM, 1 \leq M \leq 5001M500, bidders participated in the auction. We number the bidders from11 to MM. The winning bid for each lot is determined by the following rules:

? Each lot has a reserved price, which is a positive integer.

? Each bidder may submit at most one bid to each lot whose amount must be a positive integer.

? A valid bid for a lot is one that is at least the reserved price for the lot. All invalid bids are not considered.

? The largest valid bid wins the lot and is called the winning bid. In case of tie bids, the bidder with the smaller bidder number wins. If there is no valid bid for a lot, then this lot is not sold.

? The second largest bid is a valid bid that does not win if one exists; otherwise, it is the reserved price.

? If a bidder wins a lot, then the final hammer price for this lot is either 10\%10% over the second largest bid or the largest valid bid, depending on which one is smaller. If the final hammer price is not an integer, then it is truncated to the nearest integer.

? Given the reserved price and the bids for each lot, your task is to decide the total final hammer prices for a given k, 0 < k \leq M0<kM, bidders.

Input Format

The input contains N + 3 + kN+3+k lines.

Line 11: NN

Line 22: MM

Line 33: r_{1}, b_{1,1}, p_{1,1}, b_{1,2}, p{1,2}, -1r?1??,b?1,1??,p?1,1??,b?1,2??,p1,2,?1

\ldots

Line i + 2i+2: r_{i}, b_{i,1}, p_{i,1}, b_{i,2}, p{i,2}, -1r?i??,b?i,1??,p?i,1??,b?i,2??,pi,2,?1

\ldots

Line N + 2N+2: r_{N}, b_{N,1}, p_{N,1}, b_{N,2}, p_{N,2}, -1r?N??,b?N,1??,p?N,1??,b?N,2??,p?N,2??,?1

Line N + 3N+3: kk

Line N + 4N+4: q_{1}q?1??

\ldots

Line N + 3 + iN+3+i: q_{i}q?i??

\ldots

Line N + 3 + kN+3+k: q_{k}q?k??

In Line i + 2i+2, r_{i}r?i?? is the reserved price for lot ii. The number b_{i,j}b?i,j?? and p{i,j}pi,j are the j^{th}j?th?? bid for lot ii from bidder b_{i,j}b?i,j??with the amount p_{i,j}p?i,j?? . Note that a space is between each number. The number -1?1 is added to mark the end of bids for a lot. In Line N+3N+3, kk is given. In line N + 3 + iN+3+i, you are asked to provide the total hammer prices for bidder q_{i}q?i??.

Output Format:

The output contains kk lines.

Line 11: h_{1}h?1??

\ldots

Line ii: h_{i}h?i??

\ldots

Line kk: h_{k}h?k??

The total hammer prices for bidder q_{i}q?i?? is h_{i}h?i??.

Hint

In the sample, the bidder 11 got the the first lot 11 at hammer price 1313.

样例输入

3
3
11 2 12 1 15 -1
5 3 4 -1
23 1 32 2 35 3 40 -1
1
1

样例输出

13

读入奇怪咯,做到后面习惯了。
另题意不清,逛问答区已成交题习惯。他取的成交价是第二有效价格+10%和第一有效价格的最大者,这点注意到就行了。
其他就是读入sort下的事情了。
技术分享
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int N = 1005;
 4 
 5 int p[N];
 6 struct Node{
 7     int pi;
 8     int id;
 9     bool operator < (const Node &a) const {
10         if(pi == a.pi) return id < a.id;
11         return pi > a.pi;
12     }
13 };
14 
15 int main() {
16     int n, m;
17     while(cin >> n >> m) {
18         memset(p, 0, sizeof(p));
19         for(int i = 0; i < n; ++ i) {
20             int x;
21             int y;
22             int limit;
23             cin >> limit;
24             vector<Node> v;
25             v.push_back(Node{limit, 10000});
26             while(cin >> x) {
27                 if(x == -1) {
28                     break;
29                 }
30                 cin >> y;
31                 if(y >= limit) {
32                     v.push_back(Node{y, x});
33                 }
34             }
35             sort(v.begin(), v.end());
36             if(v.size() > 1) {
37                 p[v[0].id] += min(int(v[1].pi * 1.1), int(v[0].pi));
38             }
39         }
40         int k;
41         cin >> k;
42         while(k --) {
43             int x;
44             cin >> x;
45             cout << p[x] << "\n";
46         }
47     }
48     return 0;
49 }
View Code

 B. Train Seats Reservation

You are given a list of train stations, say from the station 11 to the station 100100.

The passengers can order several tickets from one station to another before the train leaves the station one. We will issue one train from the station 11 to the station 100100 after all reservations have been made. Write a program to determine the minimum number of seats required for all passengers so that all reservations are satisfied without any conflict.

Note that one single seat can be used by several passengers as long as there are no conflicts between them. For example, a passenger from station 11 to station 1010 can share a seat with another passenger from station 3030 to 6060.

Input Format

Several sets of ticket reservations. The inputs are a list of integers. Within each set, the first integer (in a single line) represents the number of orders, nn, which can be as large as 10001000. After nn, there will be nn lines representing the nnreservations; each line contains three integers s, t, ks,t,k, which means that the reservation needskk seats from the station ss to the station tt.These ticket reservations occur repetitively in the input as the pattern described above. An integer n = 0n=0 (zero) signifies the end of input.

Output Format

For each set of ticket reservations appeared in the input, calculate the minimum number of seats required so that all reservations are satisfied without conflicts. Output a single star ‘*‘ to signify the end of outputs.

样例输入

2
1 10 8
20 50 20
3
2 30 5
20 80 20
40 90 40
0

样例输出

20
60
*

日常阅读理解,队友过得。贴份队友代码。
技术分享
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const int N = 1005;
 5 ll v[N];
 6 int n;
 7 
 8 void slove(int n) {
 9     ll res = 0;
10     memset(v, 0, sizeof(v));
11             for(int i = 0; i < n; ++ i) {
12                 int s, t;
13                 ll x;
14                 cin >> s >> t >> x;
15                 for(int j = s; j < t; ++ j) {
16                     v[j] += x;
17                 }
18             }
19             for(int i = 0; i < N; ++ i) {
20                 res = max(res, v[i]);
21             }
22              cout << res << endl;
23 }
24 
25 int main() {
26     while(cin >> n) { 
27         if(n == 0) {
28             puts("*");
29         }
30         else{
31             slove(n);
32         }
33     }
34     return 0;
35 }
View Code

 

A. Weather Patterns

Consider a system which is described at any time as being in one of a set of NN distinct states, 1,2,3,...,N1,2,3,...,N. We denote the time instants associated with state changes as t = 1,2,...t=1,2,..., and the actual state at time tt as a_{ij}=p=[s_{i}=j\ |\ s_{i-1}=i], 1\le i,j \le Na?ij??=p=[s?i??=j  s?i?1??=i],1i,jN. For the special case of a discrete, first order, Markovchain, the probabilistic description for the current state (at time tt) and the predecessor state is s_{t}s?t??. Furthermore we only consider those processes being independent of time, thereby leading to the set of state transition probability a_{ij}a?ij?? of the form: with the properties a_{ij} \geq 0a?ij??0 and \sum_{i=1}^{N} A_{ij} = 1?i=1?N??A?ij??=1. The stochastic process can be called an observable Markovmodel. Now, let us consider the problem of a simple 4-state Markov model of weather. We assume that once a day (e.g., at noon), the weather is observed as being one of the following:

State 11: snow

State 22: rain

State 33: cloudy

State 44: sunny

The matrix A of state transition probabilities is:

A = \{a_{ij}\}= \begin{Bmatrix} a_{11}&a_{12}&a_{13}&a_{14} \\ a_{21}&a_{22}&a_{23}&a_{24} \\ a_{31}&a_{32}&a_{33}&a_{34} \\ a_{41}&a_{42}&a_{43}&a_{44} \end{Bmatrix}A={a?ij??}=?????????????????a?11???a?21???a?31???a?41?????a?12???a?22???a?32???a?42?????a?13???a?23???a?33???a?43?????a?14???a?24???a?34???a?44????????????????????

Given the model, several interestingquestions about weather patterns over time can be asked (and answered). We canask the question: what is the probability (according to the given model) thatthe weather for the next k days willbe? Another interesting question we can ask: given that the model is in a knownstate, what is the expected number of consecutive days to stay in that state?Let us define the observation sequence OOas O = \left \{ s_{1}, s_{2}, s_{3}, ... , s_{k} \right \}O={s?1??,s?2??,s?3??,...,s?k??}, and the probability of the observation sequence OOgiven the model is defined as p(O|model)p(Omodel). Also, let the expected number of consecutive days to stayin state ii be E_{i}E?i??. Assume that the initial state probabilities p[s_{1} = i] = 1, 1 \leq i \leq Np[s?1??=i]=1,1iN. Bothp(O|model)p(Omodel) and E_{i}E?i?? are real numbers.

Input Format

Line 11~44 for the state transition probabilities. Line 55 for the observation sequence O_{1}O?1??, and line 66 for the observation sequence O_{2}O?2??. Line 77and line 88 for the states of interest to find the expected number of consecutive days to stay in these states.

Line 11: a_{11}\ a_{12}\ a_{13}\ a_{14}a?11?? a?12?? a?13?? a?14??

Line 22: a_{21}\ a_{22}\ a_{23}\ a_{34}a?21?? a?22?? a?23?? a?34??

Line 33: a_{31}\ a_{32}\ a_{33}\ a_{34}a?31?? a?32?? a?33?? a?34??

Line 44: a_{41}\ a_{42}\ a_{43}\ a_{44}a?41?? a?42?? a?43?? a?44??

Line 55: s_{1}\ s_{2}\ s_{3}\ ...\ s_{k}s?1?? s?2?? s?3?? ... s?k??

Line 66: s_{1}\ s_{2}\ s_{3}\ ...\ s_{l}s?1?? s?2?? s?3?? ... s?l??

Line 77: ii

Line 88: jj

Output Format

Line 11 and line 22 are used to show the probabilities of the observation sequences O_{1}O?1??and O_{2}O?2?? respectively. Line 33 and line 44 are for the expected number of consecutive days to stay in states ii and jj respectively.

Line 11: p[O_{1} | model]p[O?1??model]

Line 22: p[O_{2} | model]p[O?2??model]

Line 33: E_{i}E?i??

Line 44: E_{j}E?j??

Please be reminded that the floating number should accurate to 10^{-8}10??8??.

样例输入

0.4 0.3 0.2 0.1
0.3 0.3 0.3 0.1
0.1 0.1 0.6 0.2
0.1 0.2 0.2 0.5
4 4 3 2 2 1 1 3 3
2 1 1 1 3 3 4
3
4

样例输出

0.00004320
0.00115200
2.50000000
2.00000000


前面我说错了,这才是阅读理解23333。
队友过得再贴一份队友代码:
技术分享
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3  
 4 double m[5][5], m1[5][5], ans[5][5];
 5 int a[2333333];
 6 double sum;
 7 int cnt;
 8 int k;
 9 
10 long long int read_int(){
11     char r;
12     bool start=false,neg=false;
13     long long int ret=0;
14     while(true){
15         r=getchar();
16         if((r-0<0 || r-0>9) && r!=- && !start){
17             continue;
18         }
19         if((r-0<0 || r-0>9) && r!=- && start){
20             break;
21         }
22         if(start)ret*=10;
23         start=true;
24         if(r==-)neg=true;
25         else ret+=r-0;
26     }
27     if(!neg)
28         return ret;
29     else
30         return -ret;
31 }
32  
33 int main() {
34     for (int i = 1; i <= 4; i++) {
35         for (int j = 1; j <= 4; j++) {
36             scanf("%lf", &m[i][j]);
37              scanf("\n");
38         }
39     }
40     cnt = 0;
41     sum = 1;
42     memset(ans, 0, sizeof(ans));
43     string str;
44     getline(cin, str);
45     for (int i = 0; i < str.size(); i++) {
46         if (str[i] >= 0 && str[i] <= 9){
47             a[++cnt] = str[i] - 0;
48         }
49     }
50     for (int i = 2; i <= cnt; i++){
51         sum = sum * m[a[i - 1]][a[i]];
52     }
53     printf("%.8lf\n", sum);
54     scanf("\n");
55     cnt = 0;
56     sum = 1;
57     memset(ans, 0, sizeof(ans));
58     getline(cin, str);
59     for (int i = 0; i < str.size(); i++) {
60         if (str[i] >= 0 && str[i] <= 9) {
61             a[++cnt] = str[i] - 0;
62         }
63     }
64     for (int i = 2; i <= cnt; i++) {
65         sum = sum * m[a[i - 1]][a[i]];
66     }
67     printf("%.8lf\n", sum);
68     scanf("%d", &k);
69     double temp = 1;
70     sum = 1;
71     for (int i = 2; i <= 5000000; i++) {
72         temp *= m[k][k];
73         sum += temp;
74     }
75     printf("%.8lf\n", sum);
76     scanf("%d", &k);
77     temp = 1;
78     sum = 1;
79     for (int i = 2; i <= 5000000; i++) {
80         temp *= m[k][k];
81         sum += temp;
82     }
83     printf("%.8lf\n", sum);
84     return 0;
85 }
View Code

 




2017 icpc 南宁网络赛

标签:size   image   spec   void   rate   leaves   ret   dig   oid   

原文地址:http://www.cnblogs.com/wujiechao/p/7588684.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!