a.boat Trips (water)
The main effect of the topic:
n travel routes, each tour line pi p_i people. Now there are M-boats, each with a C-man, asking whether these ships can meet all the tourist routes. Topic Analysis:
is to judge whether MC MC is all less than Pi p_i. It's too much water.
#include <bits/stdc++.h>
using namespace std;
#define RE (x) freopen (x, "R", stdin)
#define WR (x) freopen (x, "W", stdout)
#define MS (X,Y) memset (x,y,sizeof (x))
#define PB push_back
#define MP Make_pair
#define INF 0x3f3f3f3f
#define EPS 1e-8
typedef long Long ll;
typedef vector<int> VI;
typedef pair<int,int> PI;
typedef vector<ll> VL;
const int M = 1e9 + 7;
Const double PI = ACOs ( -1.0);
const int MAXN = 1E5;
const int MAXM = 1E6;
int main () {
//re ("In.txt"); WR ("OUT.txt");
int n,c,m,p;
cin>>n>>c>>m;
String s= "Yes";
while (n--) {
cin>>p;
if (c*m<p)
s= "No";
}
cout<<s<<endl;
}
b.the Great XOR (bitwise operation)
The main effect of the topic:
Enter X, ask how many a satisfied: a XOR x>x,0<a<x a\ \ xor\ \ x > x,0 Topic Analysis:
First, write the X into binary form, starting from the low position to consider:
If x is the bit 0, then as long as a in this bit 1, than his lower bit to take, can satisfy the question, if x in that bit is 0, then a can only take 0, it is impossible to find solution.
For example:
X=11001101
First A is at least one digit less than x, that is seven digits, where a is not a seven-digit, four-digit, three-digit, one-digit number (because it will be smaller after the XOR), but any six-digit, five-digit, two- digit
That would be easy. You need to be aware that the data range exceeds int.
#include <bits/stdc++.h>
using namespace std;
#define RE (x) freopen (x, "R", stdin)
#define WR (x) freopen (x, "W", stdout)
#define MS (X,Y) memset (x,y,sizeof (x))
#define PB push_back
#define MP Make_pair
#define INF 0x3f3f3f3f
#define EPS 1e-8
typedef long ll;
typedef vector<int> VI;
typedef pair<int,int> PI;
typedef vector<ll> VL;
const int M = 1e9 + 7;
Const double PI = ACOs ( -1.0);
const int MAXN = 1E5;
const int MAXM = 1E6;
ll Q,x;
int main () {
cin>>q;
while (q--) {
cin>>x;
ll Ans=0;
for (int i=0;i<35;i++) {
ll t= (1ll<<i);
if (t>=x) break
;
if (!) ( t&x))
ans+= (1ll<<i);
}
cout<<ans<<endl;
}
}
C.lucky number eight (digital DP)
The main effect of the topic:
Give you a n-bit string of numbers (the range of N to 2e5), asking how many discrete substrings can be divisible by 8. Output Results mod 1e9+7. Topic Analysis:
A look is a digital DP, the beginning of the mind flashed is the number of primary Olympiad in the 8 division of the rule is to see the end of the three digits, but the array is opened to 2E5*1000*8B=1.6GB, memory is obviously not enough.
See the puzzle know, is based on the modulus 8 value of the transfer, so that the array can only open to 2E5*8*8B=12.8MB.
And then there's the idea of a backpack, remember dp[i][j] indicates that the first I-bit has been determined, the number of methods with the current substring modulus of J, then Dp[i][j]=dp[i+1][j]+dp[i+1][k] dp[i][j]=dp[i+1][j]+dp[i+1][k], where k represents the new modulus after the i+1 bit, a bit like the idea of a backpack.
Memory Dfs, the last dp[0][0]−1 dp[0][0]-1 is the request, because it also includes an empty string, its modulus is 0. Notice the range of data.
#include <bits/stdc++.h> using namespace std; #define RE (x) freopen (x, "R", stdin) #define WR (x) freopen (x, "W", stdout) #define MS (X,y) memset (x,y,sizeof (x)) #define PB P
Ush_back #define MP Make_pair #define INF 0x3f3f3f3f #define EPS 1e-8 typedef long LL;
typedef vector<int> VI;
typedef pair<int,int> PI;
typedef vector<ll> VL;
const int M = 1e9 + 7;
Const double PI = ACOs (-1.0);
const int MAXN = 2E5;
const int MAXM = 1E6;
int n;
Char s[maxn+5];
ll DP[MAXN+5][10];
void dfs (int pos,int mod) {if (pos==n) {dp[pos][mod]= (mod==0);
Return
else if (dp[pos][mod]!=-1) return;
int nextmod= (mod*10+ (s[pos]-' 0 '))%8;
DFS (POS+1,MOD);
DFS (POS+1,NEXTMOD);
Dp[pos][mod]= (Dp[pos+1][mod]+dp[pos+1][nextmod])%m;
int main () {cin>>n;
for (int i=0;i<n;i++) cin>>s[i];
MS (DP,-1);
DFS (0,0);
cout<<dp[0][0]-1<<endl; }
D. The Value of friendship (greedy algorithm)
The main effect of the topic:
Give you n personal, M group direct friend relationship, define total value for each person's friend number (including direct and indirect) and, to find a way to add a side, so that the sum of each step is the largest summation. Topic Analysis:
First of all, for n personal circle of friends, the total value is NX (n−1) N\times (n-1), the beginning of the add Edge is 1*2+2*3+3*4...+n* (n-1). After you finish the n-1 bar, add edges to the map or manipulate it in other friends ' circles, The increase is n (n+1). Then we get the greedy law:
First count the last circle of friends have a few people, and then sorted by size, first add a circle of friends, add the second after n-1 second big ... And so on, because the first plus the largest n (n-1) value is large, so that the total value of each step is the largest
#include <bits/stdc++.h> using namespace std; #define RE (x) freopen (x, "R", stdin) #define WR (x) freopen (x, "W", stdout) #define MS (X,y) memset (x,y,sizeof (x)) #define PB P Ush_back #define MP Make_pair #define INF 0x3f3f3f3f #define EPS 1e-8 #define in "D:/water-questions/temp/input/in.txt" #
Define out "D:/water-questions/temp/input/out.txt" typedef long LL;
typedef vector<int> VI;
typedef pair<int,int> PI;
typedef vector<ll> VL;
const int M = 1e9 + 7;
Const double PI = ACOs (-1.0);
const int MAXN = 1E5;
const int MAXM = 1E6;
int q,n,m;
int f[maxn+5],r[maxn+5],sum[maxn+5];
ll ans;
int find (int x) {return f[x]==x?x:f[x]=find (f[x]);} void un (int i,int j) {int x=find (i), Y=find (j);
if (x!=y) {if (R[x]<r[y]) {f[x]=y;
SUM[Y]+=SUM[X];
else {f[y]=x;
Sum[x]+=sum[y];
if (R[x]==r[y]) r[x]++;
int main () {cin>>q; Whileq--) {cin>>n>>m;
for (int i=1;i<=n;i++) {f[i]=i;
R[i]=1;
Sum[i]=1;
for (int i=0;i<m;i++) {int u,v;
cin>>u>>v;
if (Find (U)!=find (v)) UN (U,V);
} VL CP;
for (int i=1;i<=n;i++) if (f[i]==i) CP.PB (sum[i));
Sort (Cp.begin (), Cp.end ());
ll Ans=0;
ll Edge=0;
for (int i=cp.size () -1;i>=0;i--) {edge+= (cp[i]-1);
ll Temp=0;
for (int j=1;j<cp[i];j++) temp+= (j* (J+1LL));
ans+= ((M-edge) *cp[i]* (cp[i]-1) +temp);
} cout<<ans<<endl;
}
}