zoukankan      html  css  js  c++  java
  • 每日算法

    每日算法

    those times when you get up early and you work hard; those times when you stay up late and you work hard; those times when don’t feel like working — you’re too tired, you don’t want to push yourself — but you do it anyway. That is actually the dream. That’s the dream. It’s not the destination, it’s the journey. And if you guys can understand that, what you’ll see happen is that you won’t accomplish your dreams, your dreams won’t come true, something greater will. mamba out


    那些你早出晚归付出的刻苦努力,你不想训练,当你觉的太累了但还是要咬牙坚持的时候,那就是在追逐梦想,不要在意终点有什么,要享受路途的过程,或许你不能成就梦想,但一定会有更伟大的事情随之而来。 mamba out~

    2020.3.21


    luogu-P1209 修理牛棚

    看了一眼标签搜索。。。想了一会再一看数据2^200不太对劲啊,再一看题解 贪心。。。洛谷标签这么坑的么,看了题解意思是说假设我们先将所有有牛的棚子从最小到到最大先用一块板子堵住,再将两个间隔最长的棚子之间给去掉木板 因为有 m个板子最多可以进行 m - 1次去除操作 所以减去这些间隔长度就是最终答案 唉,太菜了

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <vector>
    
    using namespace std;
    
    
    int m ,s ,c , a[205] , C[205];
    
    bool cmp(int a,int b)
    {
    	return a > b;
    }
    int main()
    {
    	cin >> m >> s >> c;
    	int id = 0;
    	for(int i = 1;i <= c ;i ++)
    	{
    		scanf("%d",&a[i]);	
    	}
    	if(m > c){
    		printf("%d
    ",c);
    		return 0;
    	} 
    	sort(a + 1, a + 1 + c);
    	
    	int ans = a[c] - a[1] + 1; // 最长的那一块木板
    	
    	for(int i = 2;i <= c; i++)
    		C[i - 1] = a[i] - a[i-1];
    	
    	sort(C + 1,C + c, cmp);
    	for(int i = 1;i <= m - 1;i ++)
    	{
    		ans = ans - C[i] + 1;
    	}
    	printf("%d
    ",ans);
    	return 0;
    }
    

    P3372 【模板】线段树 1

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <vector>
    
    using namespace std;
    const int N = 100010;
    
    typedef long long ll;
    
    ll n , m ;
    ll w[N];
    
    struct node{
    	ll l , r , sum , lazy;
    }tr[N * 4];
    
    
    void add(int u,int v)
    {
    	tr[u].lazy += v;
    	tr[u].sum += (tr[u].r - tr[u].l + 1) * v;
    	return;
    }
    
    void pushdown(int u,int l,int r)
    {
    	if(tr[u].lazy == 0)return ;
    	add(u << 1,tr[u].lazy); //下传左子树 
    	add(u << 1 | 1,tr[u].lazy);//下传右子树 
    	tr[u].lazy = 0; //取消标记 
    }
    
    
    void build(int u,int l, int r)
    {
    	if(l == r){
    		tr[u].l = l;tr[u].r = r;
    		tr[u].sum = w[r];
    	}
    	else{
    		tr[u].l = l;tr[u].r = r;
    		int mid = l + r >> 1;
    		build(u << 1,l ,mid);
    		build(u << 1 | 1,mid + 1, r);
    		tr[u].sum = tr[u << 1].sum + tr[u << 1 | 1].sum;
    	}
    }
    
    ll query(int u,int l,int r)
    {
    	if(tr[u].l >= l && tr[u].r <= r)return tr[u].sum;
    	int mid = tr[u].l + tr[u].r >> 1;
    	ll sum = 0;
    	pushdown(u , l , r);
    	if(l <= mid)sum = query(u << 1, l , r);
    	if(r > mid) sum += query(u << 1 | 1, l , r);
    	return sum;
    }
    
    void modify(int u,int l, int r,ll v)
    {
    	if(tr[u].l >= l && tr[u].r <= r)
    	{
    		return add(u,v);
    	}
    	int mid = tr[u].l + tr[u].r >> 1;
    	pushdown(u , l , r);
    	if(l <= mid)modify(u << 1,l , r , v) ;
    	if(r > mid) modify(u << 1 | 1,l , r, v);
    	tr[u].sum = tr[u << 1].sum + tr[u << 1 | 1].sum;
    } 
    
    int main()
    {
    	cin >> n >> m;
    	// 权值数组必须从1 开始 
    	for(int i = 1;i <= n ;i ++)
    	{
    		scanf("%d",&w[i]);
    	} 
    	build(1 , 1 , n); 
    	int f , x , y , k;
    	while(m--)
    	{
    		cin >> f;
    		if(f == 1)
    		{
    			cin >> x >> y >> k;
    			modify(1,x , y , k);
    		}else{
    			cin >> x >> y;
    			cout << query(1,x,y) << endl;
    		}
    	}
    	return 0;
    }
    
    
  • 相关阅读:
    查找文献的BibTex
    123. 单词搜索(DFS)
    423 Locked
    Win7 ODBC驱动 Excel (转)
    存储过程如何传变量到like下
    表的倒数第二行数据
    oracle跟踪
    PL/SQL-FOR UPDATE 与 FOR UPDATE OF的区别
    oracle for loop
    sqlserver中sp_executesql使用实例(获取动态sql输出结果)
  • 原文地址:https://www.cnblogs.com/wlw-x/p/12541862.html
Copyright © 2011-2022 走看看