1. 程式人生 > 實用技巧 >蒟蒻更菜了。。。

蒟蒻更菜了。。。

1022普及模擬

接水問題2010NOIP普及組

心情不好,只拿了30分,是因為小菜雞沒有初始化。。。

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int maxn;
 4 int n,m,a[10009],b[109],f[10009];
 5 int main(){
 6     cin>>n>>m;//n個同學m個水龍頭
 7     for(int i=1;i<=n;i++){
 8         cin>>a[i];
 9     }
10     for(int i=1;i<=n;i++){
11 if(i<=m){ 12 b[i]+=a[i]; 13 } 14 else{ 15 sort(b+1,b+m+1); 16 b[1]+=a[i]; 17 } 18 } 19 sort(b+1,b+1+m); 20 cout<<b[m]; 21 return 0; 22 }

表示式求值NOIP普及組2013

一個簡單的不得了的題讓我給寫炸了,只有20分,因為我把有用的程式碼給註釋掉了,窩太菜了QAQ。。。

 1
#include<bits/stdc++.h> 2 using namespace std; 3 const int mod=10000; 4 string str; 5 int len,num,flag,a[100009],tot=0,fl; 6 long long jg,ans; 7 int pop(){ 8 tot=tot-1; 9 return a[tot+1]; 10 } 11 int top(){ 12 return a[tot]; 13 } 14 void push(int x){ 15 a[tot+1]=x;tot++; 16 } 17 int
empty(){ 18 if(tot==0) return 1; 19 return 0; 20 } 21 int main(){ 22 cin>>str; 23 len=str.size(); 24 for(int i=0;i<len;i++){ 25 if(str[i]=='+'){ 26 push(jg);jg=0; 27 if(flag==1){ 28 int x,y,z; 29 x=pop();y=pop();z=pop(); 30 x=x*z%mod; 31 push(x); 32 flag=0; 33 } 34 if(fl==1){ 35 int x,y,z; 36 x=pop();y=pop();z=pop(); 37 x=(x+z)%mod; 38 push(x); 39 fl=0; 40 } 41 push(-2); 42 fl++; 43 } 44 else if(str[i]=='*'){ 45 push(jg);jg=0; 46 if(flag==1){ 47 int x,y,z; 48 x=pop();y=pop();z=pop(); 49 x=x*z%mod; 50 push(x); 51 } 52 53 push(-1);flag=1; 54 } 55 else{jg=jg*10+(str[i]-'0');} 56 } 57 push(jg); 58 for(int i=1;i<=flag;i++){ 59 int x,y,z; 60 x=pop();y=pop();z=pop(); 61 x=x*z%mod; 62 push(x); 63 } 64 int x,y,z; 65 x=pop();y=pop();z=pop(); 66 if(y==-1) x=x*z%mod; 67 else x=(x+z)%mod; 68 cout<<x; 69 return 0; 70 }

FBI樹NOIP普及組2004

十分妙的用字首和來判斷是否全為0,或全為1,或既有0又有1。妙啊。。。窩A了呢

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int n,mb,lf,yf,zf;//mb為長度 
 4 int sum[1030];
 5 char str[1030];
 6 void dfs(int l,int r){
 7     if(l==r){
 8         if(str[l]=='0') cout<<"B";
 9         else cout<<"I";
10         return;
11     }
12     int mid=(l+r-1)/2;//l~mid,mid+1~r;
13     dfs(l,mid);dfs(mid+1,r);
14     if(sum[r]-sum[l-1]==0) cout<<"B";
15     else if(sum[r]-sum[l-1]==r-l+1) cout<<"I";
16     else cout<<"F";
17 }
18 int main(){
19     cin>>n;
20     mb=1<<n;
21     for(int i=1;i<=mb;i++){
22         cin>>str[i];
23         sum[i]=sum[i-1]+str[i]-'0';
24     }
25     dfs(1,mb);
26     return 0;
27 }

跳房子NOIP普及組2017

老師告訴我們這是一道二分答案+DP驗證+單調佇列優化的藍題。

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 
 4 const int maxn=500000;
 5 const long long neInf=0x8080808080808080;
 6 struct gezi {
 7     int juli;
 8     int zhi;
 9 } a[maxn+1];
10 long long dp[maxn+1];
11 int q[maxn+1];
12 int n,d,k,lbound,rbound,ans=-1;
13 long long sum;
14 
15 void kuaidu(int &p) {
16     char c;
17     int f=1;
18     p=0;
19     do{
20         c=getchar();
21         if(c=='-') f=-1;
22     }while(c<'0'||c>'9');
23     do p=p*10+c-'0', c=getchar();
24     while(c>='0'&&c<='9');
25     p=p*f;
26 }
27 
28 void init() {
29     cin>>n>>d>>k;
30     for (int i=1; i<=n; i++) {
31         kuaidu(a[i].juli);
32         kuaidu(a[i].zhi);
33         if (a[i].zhi>0)
34             sum+=a[i].zhi;
35     }
36     rbound=max(a[n].juli,d);
37 }
38 
39 long long dynamic_programming(int zuo, int you) {
40     memset(dp,0x80,sizeof(dp));
41     dp[0]=0;
42     memset(q,0,sizeof(q));
43     int tou=1, wei=0, j=0;
44     /*for (int i=1; i<=n; i++)
45         for (int j=0; j<i; j++)
46             if (a[i].juli-a[j].juli>=zuo&&a[i].juli-a[j].juli<=you&&dp[j]!=neInf)
47                 dp[i]=max(dp[i],dp[j]+a[i].zhi);*/
48     for (int i=1; i<=n; i++) {
49         while (a[i].juli-a[j].juli>=zuo&&j<i) {
50             if (dp[j]!=neInf) {
51                 while (tou<=wei&&dp[q[wei]]<=dp[j])
52                     wei--;
53                 q[++wei]=j;
54             }
55             j++;
56         }
57         while (tou<=wei&&a[i].juli-a[q[tou]].juli>you)
58             tou++;
59         if (tou<=wei)
60             dp[i]=dp[q[tou]]+a[i].zhi;
61     }
62     long long num=neInf;
63     for (int i=1; i<=n; i++)
64         if (dp[i]>num)
65             num=dp[i];
66     return num;
67 }
68 
69 int main() {
70     //freopen("jump.in","r",stdin);
71     //freopen("jump.out","w",stdout);
72     init();
73     if (sum<k) {
74         cout<<"-1"<<endl;
75         return 0;
76     }
77     while (lbound<=rbound) {
78         int mid=(lbound+rbound)/2;
79         int zuobianjie=max(1,d-mid);
80         int youbianjie=d+mid;
81         long long num=dynamic_programming(zuobianjie,youbianjie);
82         if (num<k)
83             lbound=mid+1;
84         else {
85             ans=mid;
86             rbound=mid-1;
87         }
88     }
89     cout<<ans<<endl;
90     //fclose (stdin);
91     //fclose (stdout);
92     return 0;
93 }

感謝luogu題解第一篇的巨巨,窩因為時間太緊啦,決定明天再看啦,hai,還是太菜


就這樣吧,今天 sang,希望明天心情能好些。。。