2021-杭电-4-持久更新记录

简介: A . CalculusSamplesI . License Plate Recognition样例输入:样例输出:B . Kanade Loves Maze DesigningInputOutputH . Lawn of the Dead输入输出

A . Calculus


49d1cd943567432eaf18d05762a710f4.png

Samples


Input

2
1sinx+0cosx+3x+6/sinx
0


Output


NO
YES


因为给出的级数都是发散的,所以说只需要判断系数是不是都是0就好了

只有所有都是0的时候才是可以的


int main() {
  string s;
  int _ = read;
  while(_ --){
    cin >> s;
    int len = s.size(),flag = 0;
    for(int i=0;i<len;i++) if(isdigit(s[i]) && s[i] != '0' && !flag) flag = 1;
    if(!flag) puts("YES");
    else puts("NO");
  }
  return 0;
}


I . License Plate Recognition


66b9573c83bf45a59037a2a15520ca0d.png76150d4fbc3a45bf978de5a68881f5b4.pnga3285d1c086f49f0add20458b68f0f42.png


样例输入:


1
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
..........................##...........##..........#####......########..........##......########....
.......#.......#..........###..........##.........#######.....########.........###......########....
.......#.......#..........###..........##........##....##..........###.........###......##..........
.......#.......#.........####..........##...............##........###.........####......##..........
....###############......####..........##..............##........###..........####......##..........
.......#.......#.........##.#..........##..............##.......###...........####......##..........
.......#.......#.........##.##.........##..............##.......#####........#####......#######.....
.......#.......#.........##.##.........##.............##........######.......##.##......########....
.......#.......#........###.##.........##............###............##......###.##............###...
.......#########........##..##.........##...........###.............##......##..##.............##...
.......#.......#........##...#.........##...........##..............##......##..##.............##...
.......#.......#........##...##........##..........###..............##.....##...##.............##...
.......#.......#........#######........##.........###.........##....##.....#########...........##...
.......#.......#.......########........##.........##..........##....##.....#########....##.....##...
.......#########.......##....##........##........###..........###...##..........##.......##...###...
.......#.......#.......##....##........##........########......######...........##.......#######....
.......................##.....##.......##........########.......####............##........#####.....
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................
.......................................................................................................................................................................................................
....................................................................................................
..........................##...........##..........#####......########..........##......########....
.......#.......#..........###..........##.........#######.....########.........###......########....
.......#.......#..........###..........##........##....##..........###.........###......##..........
.......#.......#.........####..........##...............##........###.........####......##..........
....###############......####..........##..............##........###..........####......##..........
.......#.......#.........##.#..........##..............##.......###...........####......##..........
.......#.......#.........##.##.........##..............##.......#####........#####......#######.....
.......#.......#.........##.##.........##.............##........######.......##.##......########....
.......#.......#........###.##.........##............###............##......###.##............###...
.......#########........##..##.........##...........###.............##......##..##.............##...
.......#.......#........##...#.........##...........##..............##......##..##.............##...
.......#.......#........##...##........##..........###..............##.....##...##.............##...
.......#.......#........#######........##.........###.........##....##.....#########...........##...
.......#.......#.......########........##.........##..........##....##.....#########....##.....##...
.......#########.......##....##........##........###..........###...##..........##.......##...###...
.......#.......#.......##....##........##........########......######...........##.......#######....
.......................##.....##.......##........########.......####............##........#####.....
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................


样例输出:


Case #1:
5 19
24 32
40 41
50 58
63 70
76 84
89 97


当从前往后模拟wa了好几发之后,心情是十分复杂的;

当我点开题目里的链接看到->

faed2efb3ebd4e40951e2fdd6467379c.png

这个字的时候,心情瞬间舒畅 只有这一个字不是在左右端点之内连续的


#include <iostream>
#include <stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
char s[33][103];
bool check(int x){
    for(int i=1;i<=30;i++) if(s[i][x] == '#') return true;
    return false;
}
int main(){
    int _; cin >> _;
    for(int I = 1;I <= _;I ++){
        printf("Case #%d:\n",I);
        for(int i=1;i<=30;i++) scanf("%s",s[i]+1),s[i][0] = s[i][101] = '.';
        stack<PII> st;
        int l = 0,r = 0,cnt = 0;
        for(int i=100;i>=1;i--){
            if(check(i) && !check(i+1)) {
                r = i;
                if(cnt == 6) break;
            }
            if(check(i) && !check(i-1)) {
                l = i;
                ++ cnt;
                st.push({l,r});
            }
        }
        for(int i=1;i<=100;i++){
            if(check(i) && !check(i-1)) {
                l = i;
                break;
            }
        }
        st.push({l,r});
        while(st.size()){
            printf("%d %d\n",st.top().first,st.top().second);
            st.pop();
        }
    }
    return 0;
}


B . Kanade Loves Maze Designing


6ce15298f34144a5bf5bc164204046a2.png


Input


1
6
1 1 2 2 3
1 1 4 5 1 4


Output


495644981 518101442
495644981 518101442
397599492 896634980
612255048 326063507
495644981 518101442
397599492 896634980


746b2d2317324f8aafa37bfa298ae49a.png


#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 7;
const int mod = 1e9 + 7;
const int x = 19560929;
int idx = 0,head[maxn],ct;
ll a1[maxn],a2[maxn],cnt[maxn],a[2007][2007],w[maxn];
inline ll qPow(ll a,ll b,ll k){
    ll res = 0;
    while(b){
        if(b&1) res = (res + a) % k;
        b >>= 1;
        a = (a + a) % k;
    }
    return res;
}
struct node{
    int v,nex;
}e[maxn];
void init(){
    for(int i=0;i<maxn;i++) head[i] = -1;
    idx = 0;
}
void dfs(int u,int fa,int rt){
    for(int i=head[u];~i;i=e[i].nex){
        int to = e[i].v;
        if(to == fa) continue;
        if(cnt[w[to]] == 0) ++ ct;
        ++ cnt[w[to]];
        a[rt][to] = ct;
        dfs(to,u,rt);
        -- cnt[w[to]];
        if(cnt[w[to]] == 0) -- ct;
    }
}
void add(int u,int v){
    e[idx].v = v;
    e[idx].nex = head[u];
    head[u] = idx++;
}
int main(){
    a1[1] = a2[1] = 1;
    for(int i=2;i<=2000;i++) a1[i] = qPow(a1[i-1],x,mod),a2[i] = qPow(a2[i-1],x,mod+2);
    int _; cin >> _;
    while(_ --){
        init();
        memset(cnt,0,sizeof cnt);
        int n;
        scanf("%d",&n);
        for(int i=2;i<=n;i++){
            int v;scanf("%d",&v);
            add(i,v);
            add(v,i);
        }
        for(int i=1;i<=n;i++) scanf("%lld",&w[i]);
        for(int i=1;i<=n;i++){
            ct = 1;
            ++ cnt[w[i]];
            a[i][i] = 1;
            dfs(i,0,i);
            -- cnt[w[i]];
        }
        for(int i=1;i<=n;i++){
            ll c1 = 0,c2 = 0;
            for(int j=1;j<=n;j++){
                c1 = (c1 + a[i][j] * a1[j] % mod) % mod;
                c2 = (c2 + a[i][j] * a2[j] % (mod + 2)) % (mod + 2);
            }
            printf("%lld %lld\n",c1,c2);
        }
    }
    return 0;
}


H . Lawn of the Dead


44d66810ff094d268b756e06b1b10f40.png


输入


1
4 4 4
1 3
3 4
3 2
4 3


输出


10

给出一个 n * m的方格,其中有k个位置不能走,开始在(1,1)位置上

每次移动只能是往下或者是右移动,问能够走到的格子的数量是多少

跟lc哥学线段树 链接


#define PI (double)acos(-1.0)
#define debug(x) cout<<#x<<" :"<<x<<endl
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mid ((l+r)>>1)
struct SegmentTree{
  struct node{
    int l,r,len,sum,lazy;
  }tree[maxn << 2];
  void Pushup(int rt){
    tree[rt].sum = tree[rt<<1].sum + tree[rt<<1|1].sum;
  }
  void Pushdown(int rt){
    if(tree[rt].lazy != -1) {
      int lz = tree[rt].lazy;
      tree[rt].lazy = -1;
      tree[rt<<1].lazy = tree[rt<<1|1].lazy = lz;
      tree[rt<<1].sum = tree[rt<<1].len * lz;
      tree[rt<<1|1].sum = tree[rt<<1|1].len * lz;
    }
  }
  void Build(int rt,int l,int r){
    tree[rt] = {l,r,r-l+1,0,-1};
    if(l == r) return ;
    Build(rt<<1,l,mid);
    Build(rt<<1|1,mid+1,r);
  }
  void Update(int rt,int l,int r,int x){
    if(tree[rt].l > r || tree[rt].r < l) return ;
    if(tree[rt].l >= l && tree[rt].r <= r) {
      tree[rt].lazy = x;
      tree[rt].sum = tree[rt].len * x;
      return ;
    }
    Pushdown(rt);
    Update(rt<<1,l,r,x);
    Update(rt<<1|1,l,r,x);
    Pushup(rt);
  }
  int QuerySum(int rt,int l,int r){
    if(tree[rt].l > r || tree[rt].r < l) return 0;
    if(tree[rt].l >= l && tree[rt].r <= r) return tree[rt].sum;
    Pushdown(rt);
    return QuerySum(rt<<1,l,r) + QuerySum(rt<<1|1,l,r);
  }
  int Query(int rt,int l,int r){
    if(l > r || QuerySum(rt,l,r) == 0) return -1;
    if(tree[rt].l == tree[rt].r) return tree[rt].l;
    Pushdown(rt);
    int lval = QuerySum(rt<<1,l,r);
    int rval = QuerySum(rt<<1|1,l,r);
    if(lval) return Query(rt<<1,l,r);
    else return Query(rt<<1|1,l,r);
  }
}T[2];
vector<int> vet[maxn];
int main() {
  int _ = read;
  while(_ --){
    int n = read,m = read,k = read;
    for(int i=1;i<=m;i++) vet[i].clear(),vet[i].push_back(0);
    while(k --){
      int x = read,y = read;
      vet[y].push_back(x);
    }
    ll ans = 0;
    T[0].Build(1,1,n);
    T[1].Build(1,1,n);
    sort(vet[1].begin(),vet[1].end());
    if(vet[1].size() >= 2) T[1].Update(1,1,vet[1][1]-1,1);
    else T[1].Update(1,1,n,1);
    ans += T[1].tree[1].sum;
    for(int i=2;i<=m;i++){
      int cur = i&1,pre = cur^1;
      T[cur].Update(1,1,n,1);
      int siz = vet[i].size();  
      for(int j=0;j<siz;j++){
        int at = vet[i][j];
        int val = T[pre].Query(1,at+1,n);
        if(val == -1) T[cur].Update(1,at,n,0);
        else T[cur].Update(1,at,val-1,0);
      }
      ans += T[cur].tree[1].sum;
    }
    printf("%lld\n",ans);
  }
  return 0;
}







目录
相关文章
|
3天前
|
关系型数据库 MySQL
Mysql基础第二十三天,更新和删除数据
Mysql基础第二十三天,更新和删除数据
19 0
Mysql基础第二十三天,更新和删除数据
|
10月前
|
存储 缓存 前端开发
【Java项目】bitmap实现B站点赞超过500取消最早的点赞记录的实现思路
【Java项目】bitmap实现B站点赞超过500取消最早的点赞记录的实现思路
126 0
|
10月前
|
存储 缓存 NoSQL
项目实战典型案例1——redis只管存不管删除 让失效时间删除的问题
项目实战典型案例1——redis只管存不管删除 让失效时间删除的问题
64 0
|
10月前
|
存储 缓存 NoSQL
【项目实战典型案例】01.redis只管存不管删除让失效时间删除的问题
【项目实战典型案例】01.redis只管存不管删除让失效时间删除的问题
|
10月前
早起发现猪八戒更新了啊,把我的小八戒也更新了一下
早起发现猪八戒更新了啊,把我的小八戒也更新了一下
40 0
|
12月前
|
SQL Web App开发 安全
【永久开源】vulntarget-c 打靶记录(下)
【永久开源】vulntarget-c 打靶记录
141 0
|
12月前
|
安全 Shell 网络安全
[永久开源] vulntarget-b_打靶记录(下)
[永久开源] vulntarget-b_打靶记录
159 0
|
12月前
|
SQL 安全 Shell
[永久开源] vulntarget-b_打靶记录(上)
[永久开源] vulntarget-b_打靶记录
191 0
|
12月前
|
安全 Ubuntu 网络协议
【永久开源】vulntarget-c 打靶记录(上)
【永久开源】vulntarget-c 打靶记录
135 0
|
测试技术 数据库
LeetCode(数据库)- 每次访问的交易次数
LeetCode(数据库)- 每次访问的交易次数
185 0