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.13


    lqb 日志统计

    贪心 + 双指针

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <vector>
    #include <set> 
    using namespace std;
    const int N = 100005;
    
    int n , d , k;
    struct node{
    	int ts,id;
    };
    vector<node> v;
    set<int> ans;
    bool cmp(node a,node b)
    {
    	if(a.id == b.id)
    	{
    		return a.ts < b.ts;
    	}else return a.id < b.id;
    }
    int main()
    {
    	
    	cin >> n >> d >> k;
    	int a , b;
    	for(int i = 0;i < n ;i ++)
    	{
    		scanf("%d %d",&a , &b);
    		v.push_back({a , b});
    	} 
    	sort(v.begin() , v.end(), cmp);
    	
    	int j = 1;
    	for(int i = 0;i < v.size() ;i ++)
    	{
    		j = i + 1;
    		//printf("%d %d
    ",v[i].id , v[i].ts);
    		while(v[i].id == v[j].id)
    		{
    			if(v[j].ts - v[i].ts <= d - 1)
    			{
    				if(j - i + 1 >= k)
    				{
    					ans.insert(v[i].id);
    					break;
    				}
    			}
    			j++;
    		}
    	}
    	for(auto it = ans.begin(); it != ans.end(); it++)
    	{
    	  	cout << *it << endl; 
    	} 
    	return 0;
    } 
    

    lqb 交换瓶子

    超级大暴力

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <string>
    
    using namespace std;
    const int N = 100005;
    int f[N]  , n ;
    int main()
    {
    	cin >> n;
    	
    	for(int i = 1;i <= n ;i ++)
    	{
    		scanf("%d",&f[i]);
    	}
    	int ans = 0;
    	
    	for(int i = 1;i <= n ;i ++)
    	{
    		if(f[i] != i)
    		{
    			for(int j = i + 1;j <= n ;j ++)
    			{
    				if(f[j] == i)
    				{
    					int t = f[i];
    					f[i] = f[j];
    					f[j] = t;
    					ans++;
    					break;
    				}
    			}
    		}
    	}
    	cout << ans << endl;
    	return 0;
    }
    
  • 相关阅读:
    在Windows环境下使用docker
    C# 8.0中的模式匹配
    C# 8.0的新的using语法——Using declarations
    任务调度框架FluentScheduler简介
    任务调度框架Hangfire 简介
    Linux下的sqlserver简单试用
    使用Puppeteer进行数据抓取(五)——快速调试
    使用ptrace向已运行进程中注入.so并执行相关函数(转)
    ARM汇编编程基础之一 —— 寄存器
    ARM 汇编与C调用的若干问题(一般函数调用情况)
  • 原文地址:https://www.cnblogs.com/wlw-x/p/12489230.html
Copyright © 2011-2022 走看看