1. 程式人生 > >【2019.3.16】NOIP模擬測試190316

【2019.3.16】NOIP模擬測試190316

微笑 mil getchar() register 圖片 alt ace onclick pri

T1 澆水

  • 【題目描述】

  LazyChild在青島二中科技樓裏種了一排n棵樹,每棵樹都有一個高度。他會枚舉所有的區間,然後從區間中找出一個高度最矮的樹進行澆水(照顧弱者)。由於LazyChild澆完水之後就精疲力竭了,所以請你幫助他計算每棵樹都被澆了幾次水。

  • 【輸入文件】

  第一行一個整數n。
  第二行n個整數,分別表示每棵樹的高度。

  • 【輸出文件】

  一行n個整數用空格隔開,分別表示每棵樹被澆了幾次水。

  • 【樣例輸入】

  3
  1 3 5

  • 【樣例輸出】

  3 2 1

  • 【樣例解釋】

  LazyChild枚舉到了6個區間分別是[1], [3], [5], [1 3], [3 5], [1 3 5],對應的最矮的樹的高度是1, 3, 5, 1, 3, 1。

  • 【數據規模和約定】

  對於40%的數據,n <= 1000
  對於100%的數據,n <= 1000000,保證每棵樹的高度都不相同

  我....推了好久這個的乘法原理 我多半是廢了技術分享圖片

  然後出來之後 就這麽幾行 短小精悍蘊含無限的奧妙令人不禁伸頸側目微笑默嘆以為妙絕

技術分享圖片
 1 #include<bits/stdc++.h>
 2
using namespace std; 3 const int N=1000000+5; 4 #define ll long long 5 int n,a[N],l[N],r[N]; 6 7 template<class t>void rd(t &x) 8 { 9 x=0;int w=0;char ch=0; 10 while(!isdigit(ch)) w|=ch==-,ch=getchar(); 11 while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
12 x=w?-x:x; 13 } 14 15 int main() 16 { 17 rd(n);a[0]=a[n+1]=-1; 18 for(int i=1;i<=n;++i) rd(a[i]),l[i]=i-1,r[i]=i+1; 19 for(int i=1;i<=n;++i) while(a[l[i]]>a[i]) l[i]=l[l[i]];//向左移 20 for(int i=n;i>0;--i) while(a[r[i]]>a[i]) r[i]=r[r[i]];//向右移 21 for(int i=1;i<=n;++i) printf("%lld ",(long long)(i-l[i])*(r[i]-i));//乘法原理 22 return 0; 23 }
100昏 單調棧

T2 ABCDEF

  • 【題目描述】

  LazyChild有n個在[-30000,30000]區間內的整數,他想知道有多少個六元組(a,b,c,d,e,f)滿足: (a × b + c) ÷ d – e = f

  • 【輸入文件】

  第一行一個整數n。
  第二行n個整數。

  • 【輸出文件】

  一行一個整數,表示有多少個滿足要求的六元組。

  • 【樣例輸入】

  2
  2 3

  • 【樣例輸出】

  4

  • 【數據規模和約定】

  對於30%的數據,1 <= n <= 10
  對於100%的數據,1 <= n <= 100
因為一直咕咕咕去學hash的進程 導致看這個題 會有無數大膽的想法 最後屈服寫一個六重循環最後居然還運行錯誤我.....技術分享圖片

技術分享圖片
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define ll long long
 4 #define rg register
 5 const ll N=105;
 6 int n;
 7 ll a[N],ans=0;
 8 map<ll,ll> m;
 9 template<class t>void rd(t &x)
10 {
11     x=0;int w=0;char ch=0;
12     while(!isdigit(ch)) w|=ch==-,ch=getchar();
13     while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
14     x=w?-x:x;
15 }
16 
17 int main()
18 {
19     rd(n);
20     for(rg int i=1;i<=n;++i) rd(a[i]);
21     for(rg int ai=1;ai<=n;++ai)
22     for(rg int bi=1;bi<=n;++bi)
23     for(rg int ci=1;ci<=n;++ci)
24     ++m[a[ai]*a[bi]+a[ci]];
25     for(rg int di=1;di<=n;++di)
26     for(rg int ei=1;ei<=n;++ei)
27     for(rg int fi=1;fi<=n;++fi)
28     if(!a[di]) continue;
29     else ans+=m[(a[fi]+a[ei])*a[di]];
30     printf("%lld",ans);
31     return 0;
32 }
100昏 map

然鵝 應該用hash來寫 快的一批 map在洛谷上根本過不了

【2019.3.16】NOIP模擬測試190316