The last question of the Exercise competition has not been answered yet. To be continued
A. FAQ ~ But there was a magical error.
Return "NO ". I actually converted O to 0 ..
[Cpp]
# Include <iostream>
# Include <cstdio>
# Include <algorithm>
# Include <string>
# Include <cmath>
# Include <cstring>
# Include <queue>
# Include <set>
# Include <vector>
# Include <stack>
# Include <map>
# Include <iomanip>
# Define PI acos (-1.0)
# Deprecision Max 2005
# Define inf 1 <28
# Define LL (x) (x <1)
# Define RR (x) (x <1 | 1)
# Define FOR (I, s, t) for (int I = (s); I <= (t); ++ I)
# Define ll long
Using namespace std;
Bool cmp (int a, int B)
{
Return a> B;
} Www.2cto.com
Class CucumberMarket {
Public:
String check (vector <int> price, int budget, int k ){
Int num = price. size ();
Int * a = new int [num];
For (int I = 0; I <num; I ++)
A [I] = price [I];
Sort (a, a + num, cmp );
Int sum = 0;
For (int I = 0; I <k & I <num; I ++)
Sum + = a [I];
If (sum> budget)
Return "NO ";
Else
Return "YES ";
}
};
B. Simulate the question. Mark each 'B', and then find the next 'B' from here, traverse along the diagonal line ', compare the distance between two, sum + = min (the distance between the two, T), because it is possible that the two 'B' cannot form a straight line, because the number of T is too small, so we need to find the minimum value.
[Cpp]
Int num [100] [100];
Class PastingPaintingDivTwo {
Public:
Long countColors (vector <string> clipboard, int T ){
Memset (num, 0, sizeof (num ));
Int n, m;
For (int I = 0; I <clipboard. size (); I ++)
{
N = clipboard. size ();
For (int j = 0; j <clipboard [I]. length (); j ++)
{
M = clipboard [I]. length ();
If (clipboard [I] [j] = 'B ')
{
Num [I] [j] ++;
}
}
}
Ll sum = 0;
For (int I = 0; I <n; I ++)
{
For (int j = 0; j <m; j ++)
{
Int SPNs = 0;
Int k;
Int spp = 0;
If (num [I] [j])
{
For (k = 0; k <= min (n-I, m-j); k ++)
{
If (num [I + k] [j + k])
{
Spp + = SPNs;
SPNs = k-spp;
Sum + = min (spn, T );
}
Num [I + k] [j + k] = 0;
}
// Sum + = SPNs;
Sum + = T;
}
}
}
Return sum;
}
};