tags: to sum up
universal:
I think this test is very unsatisfactory, because of the usual habits, the basic algorithm of the bucket is not mastered, sorted before the testOnly sortThis leads to a failure to save
T3 is directly given up. At that time, I only thought that T4 can be saved.
And T4 is also analyzed, and did not think of the classification to discuss the situation from above and from the bottom, so that only playing, 10TPS
If the test can be old and old, review the basic sort and DP, maybe the result is big.
This time I also sounded my alarm, because if I can't adjust the state, the gap between others may be bigger and bigger.
improve:
T1 directly gives up
Then play T2 and T3 violence
It turns out that the above strategy is very effective.
If the T4 is not so greedy, directly discuss n = 3 I am afraid you can get more 20tps
Feeling that I am too big to increase the gap between groups, there is still a lot of things that have not been mastered.
Sound section:
universal:
Originally a binary question, but the test room is made with fast power.
There is a pit point that must be enumerated from the big to small, because if it is from small to the big, it may not be able to make it.
And N is definitely can't be used for the special time, because it must use 2 0 times, do not meet the requirements
code:
#include<cstdio>
#include<iostream>
using namespace std;
int ksm(int a,int b)
{
int ans=1;
while(b)
{
if(b&1)
{
ans=ans*a;
}
a=a*a;
b>>=1;
}
return ans;
}
int main()
{
int n;
scanf("%d",&n);
if(n%2!=0)
{
printf("-1");
return 0;
}
while(n)
{
for(int i=24;i>=1;i--)//1e7<2^24
{
if(ksm(2,i)<=n){
printf("%d ",ksm(2,i));
n-=ksm(2,i);
break;
}
}
}
return 0;
}
The test point of this topic is that it needs to be sorted in real time, while the time of the Sort is N, apparent that the time complexity of n ^ 2 is not the problem.
Then we observe W [i] <= 600, that is, we can put each W [i] in an array A, and the number of A [w [i]] is the current score into w [i] The number of people, when we look for 1 from 600, if the current total number> = max ( i ∗ w i*w i∗w%, 1), the representative has arrived as Max ( i ∗ w i*w i∗w%, 1) value, output
Time complexity is o (600 * n)
code:
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n,a[1000005],w,t[605];
int main()
{
scanf("%d%d",&n,&w);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
int p=max(1,i*w/100),now=0;// Now is the current total number of people
t[a[i]]++;
for(int j=600;i>=0;j--){
now+=t[j];
if(now>=p)
{
printf("%d ",j);
break;
}
}
}
return 0;
}
In order to solve this problem, we need to introduce a knowledge point: expression tree
Popular, in fact, it is a tree that has a child node or character, a parent node, a child.
Sample one expression tree is as follows
The value of a subtree is the value of the current subtree's left subtree and the value of the right subtree of the current subtree, the value of the current subtree root node.
Because the & calculation results are 1, there must be two are 1, then as long as the value of a subtree of the current subtree is 0, the other is not allowed to produce the result of the current subtree. influences
On the time of 1 when the & compute is 1, as long as one is 1, then as long as the value of a subtree of the current subtree is 1, the other is not allowed to produce the result of the current subtree. influences
That is, we can use an array IS to indicate whether the value of the current node will affect the value of the current node father as the root node.
Where IS [x] = 1 has no effect, IS [x] = 0 indicates an impact
It is important to note that if the current node's parent node has no effect on the value of the current subtree, no matter whether the current node reflects whether it affects the value of the current node's subtree, it will not The value of the current subtree affects
in other words,We can judge that the node has no effect on the current subtree by following the date of the parent node.
For example, IS of the current node is 0, and the IS of his father node is 1
Then we turn the IS | Father's IS of the current node, this node is IS, this node is 1
And if the IS of his father's node is 0, then explains the impact of the father's node will definitely affect the current subtree, then it can also have an impact on the current subtree, then he will influence the current child. tree
Only one of the elements of the reflusions, it is definitely impossible to reverse it with its father, then the current IS is 0, and it is sure to affect the final answer.
That is, the current node takes an impact on the father, and the father will affect the father's father. . .
Then, if the root node is 0, it will definitely affect the root node (otherwise there is a father node in the next time, then there will be no change)
So this recursive starts from the root node | 0 (| 1 words will cause all nodes to have an impact)
code:
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
char S[1000005];
int n,od[1000005];// OD is the operator of the current tree, -1 represents &, - 2 represents |, otherwise the unknown
int tree[1000005],s[1000005],top,cnt;// Tree: Each unknown Node number S: Handwritten
int l[1000005],r[1000005],a[1000005];// L: Left son R: Right son a: unknown value
bool val[1000005],is[1000005],change[1000005];// VAL: The current node is the value of the root of the root, Change: Whether the value of the current node is reversed
void xf(int now,int v){//
if(now==-1)
{
return;
}
is[now]|=v;// Father's node IS
xf(l[now],is[now]);
xf(r[now],is[now]);
}
void dfs(int now)
{
if(now==-1){
return;
}
dfs(l[now]);
dfs(r[now]);// Recurrent left and right son
if(od[now]>0)// If the current node is a number
{
val[now]=a[od[now]];// The OD exists is the current unknown subscript.
if(change[now])// If you want to reflect
{
val[now]=!val[now];
}
}
else{
if(od[now]==-1)// If you are &
{
val[now]=val[l[now]]&val[r[now]];
if(change[now])
{
val[now]=!val[now];
}
if(val[l[now]]==0)
{
is[r[now]]=1;
}
if(val[r[now]]==0)
{
is[l[now]]=1;
}
}
if(od[now]==-2)/ / Otherwise | operation
{
val[now]=val[l[now]]|val[r[now]];
if(change[now])
{
val[now]=!val[now];
}
if(val[l[now]]==1)
{
is[r[now]]=1;
}
if(val[r[now]]==1)
{
is[l[now]]=1;
}
}
}
}
int main()
{
memset(l,-1,sizeof(l));
memset(r,-1,sizeof(r));
gets(S);
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
int q;
int len=strlen(S);
for(int i=0;i<len;)
{
char c=S[i];
if(c=='x')
{
int ans=0;
i++;
while(S[i]>='0'&&S[i]<='9')
{
ans=ans*10+S[i++]-'0';
}
i--;
s[++top]=++cnt;
od[cnt]=ans;
tree[ans]=cnt;// The current node tree is numbered CNT
}
else if(c=='&')
{
int X1=s[top--],X2=s[top--];// Building a tree with the current symbol as root node
s[++top]=++cnt;/ / Because the number is saved in the stack, the value of the value is going to the expression tree.
od[cnt]=-1;
l[cnt]=X1,r[cnt]=X2;
}
else if(c=='|')
{
int X1=s[top--],X2=s[top--];
s[++top]=++cnt;
od[cnt]=-2;
l[cnt]=X1,r[cnt]=X2;
}
else if(c=='!')
{
int X1=s[top];
change[X1]=!change[X1];
}
i++;
}
int root=s[top];// Root node is the last execution
dfs(root);
bool K=val[root];/ / Ask the original value
xf(root,0);// Defense impact tag
scanf("%d",&q);
while(q--){
int x;
scanf("%d",&x);
if(is[tree[x]])// If the current node will affect the root node
{
printf("%d\n",K);
}
else{
printf("%d\n",!K);
}
}
return 0;
}
Because only go right, on, top three directions, but because of the end point in (n, m), each column is transferred from the previous column
And only three ways to transfer values
1. A [i] [j-1] + a [i] [j]
2. J-1 from above, go to A [I] [J]
3. J-1 from some point from below until A [i] [J]
That is, if you are not going to go, then you will re-rushed from the previous column.
If the resend value is larger, then it is certainly greater value to the current value, which is more advantageous for the elements below it (or above), because there must be a case is the best solution.
The three can be taken by MAX
The value of the first column is the prefix from A [1] [1] to A [N] [1] and
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
#define ll long long
int n,m;
ll a[1005][1005],dp[1005][1005];
int main()
{
memset(dp,-0x3f,sizeof(dp));
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
scanf("%lld",&a[i][j]);
}
}
dp[1][1]=a[1][1];
for(int i=2;i<=n;i++)
{
dp[i][1]=dp[i-1][1]+a[i][1];
}
for(int j=2;j<=m;j++)
{
ll now=-1e17;
for(int i=1;i<=n;i++)
{
now=max(now,dp[i][j-1]);// If now is updated by DP [i] [J-1], the case 1
now+=a[i][j];/ / Otherwise, the situation 2
dp[i][j]=max(dp[i][j],now);
}
now=-1e17;
for(int i=n;i>=1;i--)
{
now=max(now,dp[i][j-1]);// If now is updated by DP [i] [J-1], the case 1
now+=a[i][j];/ / Otherwise, the situation 3
dp[i][j]=max(dp[i][j],now);
}
}
printf("%lld",dp[n][m]);
return 0;
}
improve:
In fact, we can put all the animals in all existing zoo, so that each animal needs to feed in the final animal.
If the final animal & p [i] is not the final animal, that is, the final animal P (I] is 0, then this kind of feed animal can not meet
That is, binary first P [I] is not a number of 1.
Will it be half of the total number of animals
So k-, current P [i] has been found, so Vis [p [i]] = 1
Finally output POW (2, k)
K = 64, N = 0 special circumstances will be super ULL, you can
code:
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
unsigned long long n,m,c,k,sum,ans;
bool vis[1000005];
int main()
{
scanf("%llu%llu%llu%llu",&n,&m,&c,&k);
for(unsigned long long i=1;i<=n;i++)
{
unsigned long long p;
scanf("%llu",&p);
sum|=p;
}
for(unsigned long long i=1;i<=m;i++)
{
unsigned long long p,q;
scanf("%llu%llu",&p,&q);
if((sum|(1ull<<p))!=sum&&!vis[p])
{
k--;
vis[p]=true;
}
}
if(k==64&&n==0)
{
printf("18446744073709551616");
return 0;
}
printf("%llu",(unsigned long long)pow(2,k)-n);// N animals have already, so minus
return 0;
}
Three years, a string, this year is taking it.
T1 is a topology sort, but it needs high precision
Because a water storage point wants to drain, you must wait until it is in the water sear of each father's day.
Also because the pipeline has no ring, there is definitely no parent node of the child node to drain the parent node.
When the exam, I used a CNT array to save the number, and then I think that it is a topology.
T2, because I don't know how to judge the odd number of characters, but haven't hired, haveh and kmp I have thought of it.
T3 will not
T4 violent simulation
T1 does not add high Code:
#include<cstdio>
#include<iostream>
#include<vector>
using namespace std;
int n,m,P[1000005],cnt,vis[1000005],Cnt[1000005];
struct water{
long long out,in;
vector<int> v;
}a[1000005];
long long Gcd(long long a,long long b){
return b==0?a:Gcd(b,a%b);
}
long long Lcm(long long a,long long b)
{
return a*b/(Gcd(a,b));
}
void dfs(int now,long long In,long long Out)
{
if(a[now].in==0)
{
a[now].in=In;
a[now].out=Out;
}
else{
long long K=Lcm(a[now].out,Out);
a[now].in=a[now].in*(K/a[now].out);
a[now].in+=In*(K/Out);
a[now].out=K;
}
long long O=Gcd(a[now].in,a[now].out);
a[now].in/=O;
a[now].out/=O;
vis[now]++;
if(vis[now]==Cnt[now])
{
for(int i=0;i<a[now].v.size();i++)
{
dfs(a[now].v[i],a[now].in,a[now].out*a[now].v.size());
}
}
}
int main()
{
//freopen("water.in","r",stdin);
//freopen("water.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
int p,x;
scanf("%d",&p);
if(p==0)
{
P[++cnt]=i;
}
else{
for(int j=1;j<=p;j++)
{
scanf("%d",&x);
Cnt[x]++;
a[i].v.push_back(x);
}
}
}
for(int i=1;i<=m;i++)
{
Cnt[i]=1;
dfs(i,a[i].v.size(),a[i].v.size());
}
for(int i=1;i<=cnt;i++)
{
long long k=Gcd(a[P[i]].in,a[P[i]].out);
printf("%lld %lld\n",a[P[i]].in/k,a[P[i]].out/k);
}
return 0;
}
Is a template summary to be updated. The basic data structure KMP string pattern matching Next [i] represents the non-prefix to a prefix A substring i to A end of the maximum length can be matched. f ...
NOIP Graph Theory Summary NOIP2013 trucking Algorithm: maximum spanning tree, doubling LCA ideas: FIG guaranteed after Unicom, the minimum spanning tree found smaller than the maximum side edges have ...
NOIP 2017 Day1 summary Problem-solving program Foreword: The test is very poor, the compiler version is too low, not adapted to the environment, resulting in serious errors in the second question. T1 ...
NOIP 2017 Day2 summary Foreword: The test was very poor. I spent a lot of time thinking about T2, but I still didn't play it out. I only committed violence. When using DP to recurse equations, there a...
//I would like to test my NOIP with this document Although this test was exploded, after all, it is a grassroots player with a 0-based junior high school. It is also good to have this experience o...
Finally finished noip, theoretically a number theory problem (in fact, I finished it half a month ago) I have to say that noip's number theory is still difficult and troublesome. But most of them are ...
The last two questions (flying birds, crossing the river) giant pit, I directly did two days + two nights ( Haven't done it yet) Really failed Let me talk about the characteristics of the topic: Subst...
[Note: The code is all placed in the last link] Day1 T1 Xiaokai's doubts [Topic description] Xiaokai has two denominations of gold coins, both denominations are positive integers and mutually prime. X...
The world is really big After the test is over, NOIP is afraid to kneel It is reasonable to get 100 points on the three water questions today. The card in the first question is often stuck with 20 poi...
(To commemorate the defending champion S7 who died in the top 8) Big in the world Test today, the second test of number theory How do you say, today’s estimated best score should be 240, but the...