2017 icpc 南宁网络赛
2000年台湾大专题。。。英语阅读输入输出专场。。我只能说很强势。。
The frequent subset problem is defined as follows. Suppose UU={1, 2,\ldots…,N} is the universe, and S_{1}S1, S_{2}S2,\ldots…,S_{M}SM are MM sets over UU. Given a positive constant \alphaα, 0<\alpha \leq 10<α≤1, a subset BB (B \neq 0B≠0) is α-frequent if it is contained in at least \alpha MαM sets of S_{1}S1, S_{2}S2,\ldots…,S_{M}SM, i.e. \left | \left \{ i:B\subseteq S_{i} \right \} \right | \geq \alpha M∣{i:B⊆Si}∣≥α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\}S1={1,5}, S_{2}=\{1,2,5\}S2={1,2,5}, S_{3}=\{1,3,4\}S3={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}Si, 1 \le i \le M1≤i≤M . 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里面有几个枚举集合是他的子集。把两个数字或一下如果是子集的话数字不变,不是则改变。
#include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define LL long long
#define mod 1000000007
using namespace std;
const int N=1e2+;
int vis[N][N];
int num[N];
int n,m,T,k,ct,len,p,gg,tt;
double aef;
string s;
int main()
{
scanf("%d%lf",&n,&aef);
m=;
clr(vis);
clr(num);
getline(cin,s);
while(getline(cin,s))
{
m++;
k=;
for(int i=;i<s.size();i++)
if(s[i]>'' || s[i]<'')
{
vis[m][k]++;
k=;
}
else
{
k*=;
k+=s[i]-'';
}
vis[m][k]++;
for(int i=;i<=n;i++)
{
if(vis[m][i])
num[m]|=(<<(i-));
}
}
tt=m;
if(abs(m*aef-(int)(m*aef))<=1e-)
tt=(int)(m*aef+0.5);
else
tt=m*aef+;
p=;
len=(<<n);
for(int i=;i<len;i++)
{
ct=;
for(int j=;j<=m;j++)
if((i|num[j])==num[j])
ct++;
if(ct>=tt)
p++;
}
printf("%d\n",p);
return ;
}
L, The Heaviest Non-decreasing Subsequence Problem
Let SS be a sequence of integers s_{1}s1, s_{2}s2, ......, s_{n}snEach 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}si is s_{i}-10000si−10000 . For example, if s_{i}siis 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}si1, s_{i2}si2, ......, s_{ik}sik, with i_{1}<i_{2}\ ...\ <i_{k}i1<i2 ... <ik, such that, for all 1 \leq j<k1≤j<k, we have s_{ij}<s_{ij+1}sij<sij+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:
8080 7575 7373 9393 7373 7373 1010110101 9797 -1−1 -1−1 114114 -1−11011310113 118118
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∗105
Input Format
A list of integers separated by blanks:s_{1}s1, s_{2}s2,......,s_{n}sn
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做法。
#include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define LL long long
#define mod 1000000007
using namespace std;
const int N=1e4+;
const int NN=1e4+;
const int M=2e5+;
int bit[N];
int val[M],wei[M],ans,maxn;
int sum(int i)
{
int s=;
while(i>)
{
s=max(s,bit[i]);
i-=i&-i;
}
return s;
}
void add(int i,int x)
{
while(i<=NN)
{
bit[i]=max(bit[i],x);
i+=i&-i;
}
return ;
}
int ct,n,m,k,T;
int main()
{
n=;
while(scanf("%d",&val[n])!=EOF)
{
if(val[n]>=)
n++;
}
n--;
for(int i=;i<=n;i++)
{
if(val[i]>=)
{
val[i]-=;
wei[i]=;
}
else
wei[i]=;
}
clr(bit);
maxn=;
for(int i=;i<=n;i++)
{
ans=sum(val[i])+wei[i];
maxn=max(maxn,ans);
add(val[i],ans);
}
printf("%d\n",maxn);
return ;
}
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}Sn, 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}x1 x2 ... xnwhich is any permutation of the n digits {1, 2, 3, ..., n}1,2,3,...,n. For instance, an S_{4}S4 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}x1 x2x3 x4 ... xn, it has n-1n−1 edges connecting to nodes x_{2}\ x_{1}\ x_{3}\ x_{4}\ ...\ x_{n}x2 x1 x3 x4 ... xn, x_{3}\ x_{2}\ x_{1}\ x_{4}\ ...\ x_{n}x3 x2 x1 x4 ... xn, x_{4}\ x_{2}\ x_{3}\ x_{1}\ ...\ x_{n}x4 x2 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}abcd3 x1 ... xn, ..., and xn x2 x3 x4 ... x1. That is, the n−1adjacent nodes are obtained by swapping the first symbol and the d−th symbol of x1 x2 x3 x4 ... xn, for d=2,...,n. For instance, in S4, node 1234 has 3 edges connecting to nodes 2134, 3214, and 4231. The following figure shows how S4 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}x1 x_{2}x2 x_{3}x3 ... x_{n}xn and y_{1}y1 y_{2}y2 y_{3}\ ...\ y_{n}y3 ... yn in S_{n}Sn.
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。
#include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define LL long long
#define mod 1000000007
using namespace std;
const int N=1e2+;
const int NN=1e4+;
const int M=2e5+;
int n;
string s1,s2;
int num[N],ct,flag=;;
int main()
{
scanf("%d",&n);
for(int kase=;kase<=;kase++)
{
cin>>s1;
cin>>s2;
for(int i=;i<s2.size();i++)
num[s2[i]-'']=i;
ct=;
flag=;
for(int i=;i<s1.size();i++)
{
if(s1[i]!=s2[i] && i>)
flag++;
while(s1[i]!=s2[i])
{
swap(s1[i],s1[num[s1[i]-'']]);
ct++;
}
}
if(flag)
ct+=*flag;
printf("%d\n",ct);
}
return ;
}
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内存怎么分配。。
学过计组,英语好的话你就懂了。。。
//zq's code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = ;
const int cacheSize = ;
const int lineSize = ; int cnt[N];
string s;
int a, b; void slove() {
memset(cnt, -, sizeof(cnt));
a = ;
b = ;
while(cin >> s){
if(s == "END") break;
b ++;
int ans = ;
for(int i = ; i < s.size(); ++ i) {
int tmp;
if(s[i] >= 'A') {
tmp = s[i] - 'A' + ;
}
else {
tmp = s[i] - '';
}
ans = ans * + tmp;
}
ans = ans / cacheSize; if(cnt[ans%lineSize] == ans) {
puts("Hit");
++ a;
}
else {
puts("Miss");
}
cnt[ans%lineSize] = ans;
}
printf("Hit ratio = %.2lf", 100.0 * a / b);
puts("%");
} int main() {
slove();
return ;
}
G.Finding the Radius for an Inserted Circle
Three circles C_{a}Ca, C_{b}Cb, and C_{c}Cc, all with radius RRand tangent to each other, are located in two-dimensional space as shown in Figure 11. A smaller circle C_{1}C1 with radius R_{1}R1 (R_{1}<RR1<R) is then inserted into the blank area bounded by C_{a}Ca, C_{b}Cb, and C_{c}Cc so that C_{1}C1 is tangent to the three outer circles, C_{a}Ca, C_{b}Cb, and C_{c}Cc. Now, we keep inserting a number of smaller and smaller circles C_{k}\ (2 \leq k \leq N)Ck (2≤k≤N) with the corresponding radius R_{k}Rk into the blank area bounded by C_{a}Ca, C_{c}Cc and C_{k-1}Ck−1 (2 \leq k \leq N)(2≤k≤N), so that every time when the insertion occurs, the inserted circle C_{k}Ck is always tangent to the three outer circles C_{a}Ca, C_{c}Cc and C_{k-1}Ck−1, as shown in Figure 11
Figure 1.
(Left) Inserting a smaller circle C_{1}C1 into a blank area bounded by the circle C_{a}Ca, C_{b}Cb and C_{c}Cc.
(Right) An enlarged view of inserting a smaller and smaller circle C_{k}Ck into a blank area bounded by C_{a}Ca, C_{c}Cc and C_{k-1}Ck−1 (2 \leq k \leq N2≤k≤N), so that the inserted circle C_{k}Ck is always tangent to the three outer circles, C_{a}Ca, C_{c}Cc, and C_{k-1}Ck−1.
Now, given the parameters RR and kk, please write a program to calculate the value of R_{k}Rk, i.e., the radius of the k-thk−th inserted circle. Please note that since the value of R_kRk may not be an integer, you only need to report theinteger part of R_{k}Rk. For example, if you find that R_{k}Rk = 1259.89981259.8998 for some kk, then the answer you should report is 12591259.
Another example, if R_{k}Rk = 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 10N≤10. Furthermore, you may assume \pi = 3.14159π=3.14159. The range of each parameter is as below:
1 \leq k \leq N1≤k≤N, and 10^{4} \leq R \leq 10^{7}104≤R≤107.
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: kk R_{k}Rk ----------------output for the value ofkk and R_{k}Rk at the test case #11, each of which should be separated by a blank.
\ldots…
Line ii: kk R_{k}Rk ----------------output for kk and the value of R_{k}Rk at the test case # ii, each of which should be separated by a blank.
Line ll: kk R_{k}Rk ----------------output for kk and the value ofR_{k}Rk 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。
#include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define LL long long
#define mod 1000000007
using namespace std;
const int N=1e2+;
double rk[N];
double r,t,lefted,R;
int n,T,k,q;
int main()
{
while(scanf("%d",&n)!=EOF && n!=-)
{
scanf("%lf",&R);
rk[]=R;
lefted=sqrt()*R;
for(int i=;i>=;i--)
{
t=lefted-rk[i+];
rk[i]=t*t//(t+R);
lefted=lefted-rk[i+]-rk[i];
}
for(int i=;i<=;i++)
swap(rk[i],rk[-i+]);
for(int i=;i<=n;i++)
{
scanf("%d",&q);
printf("%d %d\n",q,int(rk[q]+(1e-)));
}
}
return ;
}
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
*
扫描线求面积并题。放个队友代码~
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring> using namespace std; typedef long long ll;
const int inf = 0x3f3f3f3f;
const int MAXN = ;
int n;
int t[MAXN];
int HASH[MAXN],sum[MAXN];
struct data{
int x1,x2,y;int f;
}a[MAXN];
inline bool operator<(data a,data b){
return a.y<b.y;
}
int findup(int x)
{
int l=,r=*n;
while(l<=r)
{
int mid=(l+r)>>;
if(HASH[mid]<x)l=mid+;
else if(HASH[mid]==x)return mid;
else r=mid-;
}
}
void PUSHUP(int k,int l,int r)
{
if(t[k])
sum[k]=HASH[r+]-HASH[l];
else if(l==r)
sum[k]=;
else
sum[k]=sum[k<<]+sum[k<<|];
}
void update(int k,int l,int r,int x,int y,int f)
{
if(x==l&&y==r)
{
t[k]+=f;PUSHUP(k,l,r);
return;
}
int mid=(l+r)>>;
if(y<=mid)
update(k<<,l,mid,x,y,f);
else if(x>mid)
update(k<<|,mid+,r,x,y,f);
else
{
update(k<<,l,mid,x,mid,f);
update(k<<|,mid+,r,mid+,y,f);
}
PUSHUP(k,l,r);
}
void solve(){
memset(t,,sizeof(t));
memset(sum,,sizeof(sum));
int x1,y1,x2,y2;
for(int i=;i<=n;i++){
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
a[*i-].x1=a[*i].x1=x1;
a[*i-].x2=a[*i].x2=x2;
a[*i-].y=y1;a[*i].y=y2;
a[*i-].f=;a[*i].f=-;
HASH[*i-]=x1;HASH[*i]=x2;
}
sort(HASH+,HASH+*n+);
sort(a+,a+*n+);
int ans=;
for(int i=;i<=*n;i++){
int l=findup(a[i].x1),r=findup(a[i].x2)-;
if(l<=r)update(,,*n,l,r,a[i].f);
ans+=sum[]*(a[i+].y-a[i].y);
}
printf("%d\n",ans);
}
int main()
{
while(scanf("%d",&n))
{
if(n==){
printf("*\n");
break;
}
solve();
}
return ;
}
Company ABC is holding an antique auction. In the auction, there are NN, 1 \leq N \leq 10001≤N≤1000, lots. We number the lots from 11 to NN. There are MM, 1 \leq M \leq 5001≤M≤500, 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<k≤M, 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}, -1r1,b1,1,p1,1,b1,2,p1,2,−1
\ldots…
Line i + 2i+2: r_{i}, b_{i,1}, p_{i,1}, b_{i,2}, p{i,2}, -1ri,bi,1,pi,1,bi,2,pi,2,−1
\ldots…
Line N + 2N+2: r_{N}, b_{N,1}, p_{N,1}, b_{N,2}, p_{N,2}, -1rN,bN,1,pN,1,bN,2,pN,2,−1
Line N + 3N+3: kk
Line N + 4N+4: q_{1}q1
\ldots…
Line N + 3 + iN+3+i: q_{i}qi
\ldots…
Line N + 3 + kN+3+k: q_{k}qk
In Line i + 2i+2, r_{i}ri is the reserved price for lot ii. The number b_{i,j}bi,j and p{i,j}pi,j are the j^{th}jth bid for lot ii from bidder b_{i,j}bi,jwith the amount p_{i,j}pi,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}qi.
Output Format:
The output contains kk lines.
Line 11: h_{1}h1
\ldots…
Line ii: h_{i}hi
\ldots…
Line kk: h_{k}hk
The total hammer prices for bidder q_{i}qi is h_{i}hi.
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下的事情了。
#include <bits/stdc++.h>
using namespace std;
const int N = ; int p[N];
struct Node{
int pi;
int id;
bool operator < (const Node &a) const {
if(pi == a.pi) return id < a.id;
return pi > a.pi;
}
}; int main() {
int n, m;
while(cin >> n >> m) {
memset(p, , sizeof(p));
for(int i = ; i < n; ++ i) {
int x;
int y;
int limit;
cin >> limit;
vector<Node> v;
v.push_back(Node{limit, });
while(cin >> x) {
if(x == -) {
break;
}
cin >> y;
if(y >= limit) {
v.push_back(Node{y, x});
}
}
sort(v.begin(), v.end());
if(v.size() > ) {
p[v[].id] += min(int(v[].pi * 1.1), int(v[].pi));
}
}
int k;
cin >> k;
while(k --) {
int x;
cin >> x;
cout << p[x] << "\n";
}
}
return ;
}
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
*
日常阅读理解,队友过得。贴份队友代码。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = ;
ll v[N];
int n; void slove(int n) {
ll res = ;
memset(v, , sizeof(v));
for(int i = ; i < n; ++ i) {
int s, t;
ll x;
cin >> s >> t >> x;
for(int j = s; j < t; ++ j) {
v[j] += x;
}
}
for(int i = ; i < N; ++ i) {
res = max(res, v[i]);
}
cout << res << endl;
} int main() {
while(cin >> n) {
if(n == ) {
puts("*");
}
else{
slove(n);
}
}
return ;
}
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 Naij=p=[si=j ∣ si−1=i],1≤i,j≤N. 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}st. Furthermore we only consider those processes being independent of time, thereby leading to the set of state transition probability a_{ij}aij of the form: with the properties a_{ij} \geq 0aij≥0 and \sum_{i=1}^{N} A_{ij} = 1∑i=1NAij=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={aij}=⎩⎪⎪⎨⎪⎪⎧a11a21a31a41a12a22a32a42a13a23a33a43a14a24a34a44⎭⎪⎪⎬⎪⎪⎫
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={s1,s2,s3,...,sk}, and the probability of the observation sequence OOgiven the model is defined as p(O|model)p(O∣model). Also, let the expected number of consecutive days to stayin state ii be E_{i}Ei. Assume that the initial state probabilities p[s_{1} = i] = 1, 1 \leq i \leq Np[s1=i]=1,1≤i≤N. Bothp(O|model)p(O∣model) and E_{i}Ei are real numbers.
Input Format
Line 11~44 for the state transition probabilities. Line 55 for the observation sequence O_{1}O1, and line 66 for the observation sequence O_{2}O2. 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}a11 a12 a13 a14
Line 22: a_{21}\ a_{22}\ a_{23}\ a_{34}a21 a22 a23 a34
Line 33: a_{31}\ a_{32}\ a_{33}\ a_{34}a31 a32 a33 a34
Line 44: a_{41}\ a_{42}\ a_{43}\ a_{44}a41 a42 a43 a44
Line 55: s_{1}\ s_{2}\ s_{3}\ ...\ s_{k}s1 s2 s3 ... sk
Line 66: s_{1}\ s_{2}\ s_{3}\ ...\ s_{l}s1 s2 s3 ... sl
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}O1and O_{2}O2 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[O1∣model]
Line 22: p[O_{2} | model]p[O2∣model]
Line 33: E_{i}Ei
Line 44: E_{j}Ej
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。
队友过得再贴一份队友代码:
#include <bits/stdc++.h>
using namespace std; double m[][], m1[][], ans[][];
int a[];
double sum;
int cnt;
int k; long long int read_int(){
char r;
bool start=false,neg=false;
long long int ret=;
while(true){
r=getchar();
if((r-''< || r-''>) && r!='-' && !start){
continue;
}
if((r-''< || r-''>) && r!='-' && start){
break;
}
if(start)ret*=;
start=true;
if(r=='-')neg=true;
else ret+=r-'';
}
if(!neg)
return ret;
else
return -ret;
} int main() {
for (int i = ; i <= ; i++) {
for (int j = ; j <= ; j++) {
scanf("%lf", &m[i][j]);
scanf("\n");
}
}
cnt = ;
sum = ;
memset(ans, , sizeof(ans));
string str;
getline(cin, str);
for (int i = ; i < str.size(); i++) {
if (str[i] >= '' && str[i] <= ''){
a[++cnt] = str[i] - '';
}
}
for (int i = ; i <= cnt; i++){
sum = sum * m[a[i - ]][a[i]];
}
printf("%.8lf\n", sum);
scanf("\n");
cnt = ;
sum = ;
memset(ans, , sizeof(ans));
getline(cin, str);
for (int i = ; i < str.size(); i++) {
if (str[i] >= '' && str[i] <= '') {
a[++cnt] = str[i] - '';
}
}
for (int i = ; i <= cnt; i++) {
sum = sum * m[a[i - ]][a[i]];
}
printf("%.8lf\n", sum);
scanf("%d", &k);
double temp = ;
sum = ;
for (int i = ; i <= ; i++) {
temp *= m[k][k];
sum += temp;
}
printf("%.8lf\n", sum);
scanf("%d", &k);
temp = ;
sum = ;
for (int i = ; i <= ; i++) {
temp *= m[k][k];
sum += temp;
}
printf("%.8lf\n", sum);
return ;
}
2017 icpc 南宁网络赛的更多相关文章
- 2017 icpc 沈阳网络赛
cable cable cable Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- 2017 icpc 西安网络赛
F. Trig Function 样例输入 2 0 2 1 2 2 样例输出 998244352 0 2 找啊找啊找数列和论文.cosnx可以用切比雪夫多项式弄成(cosx)的多项式,然后去找到了相关 ...
- 2018 ICPC 沈阳网络赛
2018 ICPC 沈阳网络赛 Call of Accepted 题目描述:求一个算式的最大值与最小值. solution 按普通算式计算方法做,只不过要同时记住最大值和最小值而已. Convex H ...
- 2018 ICPC 徐州网络赛
2018 ICPC 徐州网络赛 A. Hard to prepare 题目描述:\(n\)个数围成一个环,每个数是\(0\)~\(2^k-1\),相邻两个数的同或值不为零,问方案数. solution ...
- hdu6212[区间dp] 2017青岛ACM-ICPC网络赛
原题: BZOJ1032 (原题数据有问题) /*hdu6212[区间dp] 2017青岛ACM-ICPC网络赛*/ #include <bits/stdc++.h> using name ...
- 2019 ICPC 南昌网络赛
2019 ICPC 南昌网络赛 比赛时间:2019.9.8 比赛链接:The 2019 Asia Nanchang First Round Online Programming Contest 总结 ...
- 2018 ICPC 焦作网络赛 E.Jiu Yuan Wants to Eat
题意:四个操作,区间加,区间每个数乘,区间的数变成 2^64-1-x,求区间和. 题解:2^64-1-x=(2^64-1)-x 因为模数为2^64,-x%2^64=-1*x%2^64 由负数取模的性质 ...
- 2017年icpc西安网络赛 Maximum Flow (找规律+数位dp)
题目 https://nanti.jisuanke.com/t/17118 题意 有n个点0,1,2...n-1,对于一个点对(i,j)满足i<j,那么连一条边,边权为i xor j,求0到n- ...
- 2017南宁网络赛 Problem J Minimum Distance in a Star Graph ( 模拟 )
题意 : 乱七八糟说了一大堆,实际上就是问你从一个序列到另个序列最少经过多少步的变化,每一次变化只能取序列的任意一个元素去和首元素互换 分析 : 由于只能和第一个元素去互换这种操作,所以没啥最优的特别 ...
随机推荐
- 【HDU】2222 Keywords Search
[算法]AC自动机 [题解]本题注意题意是多少关键字能匹配而不是能匹配多少次,以及可能有重复单词. 询问时AC自动机与KMP最大的区别是因为建立了trie,所以对于目标串T与自动机串是否匹配只需要直接 ...
- R、Python、Scala和Java,到底该使用哪一种大数据编程语言?
有一个大数据项目,你知道问题领域(problem domain),也知道使用什么基础设施,甚至可能已决定使用哪种框架来处理所有这些数据,但是有一个决定迟迟未能做出:我该选择哪种语言?(或者可能更有针对 ...
- Windows Server 2008 R2 SP1安装SQL 2012安装报错之0x858C001B
使用Windows Server 2008 R2 SP1安装SQL 2012的时候总是报这样一个错: SQL Server Setup has encountered the following er ...
- 如何入门 Python 爬虫?
作者:谢科 来源:知乎链接:https://www.zhihu.com/question/20899988/answer/24923424 著作权归作者所有.商业转载请联系作者获得授权,非商业转载 ...
- Double类型的数据四舍五入保留小数点后两位
4种方法,都是四舍五入,例: import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberF ...
- 11个让你吃惊的linux命令
我已经用了十年的Linux了,通过今天这篇文章我将向大家展示一系列的命令.工具和技巧,我希望一开始就有人告诉我这些,而不是曾在我成长道路上绊住我. AD: 我已经用了十年的Linux了,通过今天这篇文 ...
- linux安装lamp
github https://github.com/zblogcn/zblogphp Installation If your server system: CentOS yum -y install ...
- 【swupdate文档 一】嵌入式系统的软件管理
嵌入式系统的软件管理 嵌入式系统变得越来越复杂, 它们的软件也反映了这种复杂性的增加. 为了支持新的特性和修复,很有必要让嵌入式系统上的软件 能够以绝对可靠的方式更新. 在基于linux的系统上,我们 ...
- 网络知识===关于MAC地址和IP不能互相替代,缺一不可的原因
最近在看书<图解TCP/IP>书中分别谈到了IP和MAC地址.于是我就有两个疑惑, 为什么有了IP地址,我们还要获取MAC地址? 为什么我们初始不直接使用MAC地址作为终点地址?还要那么复 ...
- 【bzoj4567】SCOI2016背单词
题号莫名喜感. 倒序建Trie,dfs这棵Trie,贪心一下,每次按照size排序计算贡献就好. #include<bits/stdc++.h> #define N 100010 #def ...