标签:for math.h cond 技术 names number push als preview
Time Limit:2s Memory Limit:128MByte
Submissions:1599Solved:270
You have a sequence anan, which satisfies:
Now you should find the value of ?10an??10an?.
#include <stdio.h> #include <math.h> int pow10(int i){ int ans=1; for(int j=0;j<i;j++) ans*=10; return ans; } int main(){ int n; while(~scanf("%d",&n)){ int ans=n+(int)log10(n*1.0); if(n==10)ans-=1; for(int i=2;i<=9;i++){ int x=pow10(i); if(x+1-i<n&&n<x) ans++; } printf("%d\n",ans); } return 0;}
Time Limit:2s Memory Limit:128MByte
Submissions:699Solved:186
There are nn buildings lined up, and the height of the ii-th house is hihi.
An inteval [l,r][l,r](l≤r)(l≤r) is harmonious if and only if max(hl,…,hr)?min(hl,…,hr)≤kmax(hl,…,hr)?min(hl,…,hr)≤k.
Now you need to calculate the number of harmonious intevals.
#include <bits/stdc++.h> #define LL long long using namespace std; const int maxN = 2e5+10; int n, k, a[maxN]; LL ans; void input() { scanf("%d%d", &n, &k); for (int i = 0; i < n; ++i) scanf("%d", &a[i]); } void work() { ans = 0; deque<int> mi, ma; int p = 0; for (int i = 0; i < n; ++i) { while (!(mi.empty() && ma.empty()) && !(abs(a[i]-a[mi.front()]) <= k && abs(a[i]-a[ma.front()]) <= k)) { p++; while (!mi.empty() && mi.front() < p) mi.pop_front(); while (!ma.empty() && ma.front() < p) ma.pop_front(); } ans += i-p+1; while (!mi.empty() && a[mi.back()] > a[i]) mi.pop_back(); mi.push_back(i); while (!ma.empty() && a[ma.back()] < a[i]) ma.pop_back(); ma.push_back(i); } printf("%lld\n", ans); } int main() { input(); work(); return 0; }
标签:for math.h cond 技术 names number push als preview
原文地址:http://www.cnblogs.com/BobHuang/p/7258287.html