• 每日算法


    每日算法

    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;
    }
    
  • 相关阅读:
    [你必须知道的异步编程]——基于事件的异步编程模式
    [.Net线程处理系列]专题三:线程池中的I/O线程
    [.Net 线程处理系列]专题一:线程基础
    [.Net线程处理系列]专题四:线程同步
    [你必须知道的异步编程]——异步编程模型(APM)
    C#软件程序无法启动的故障
    CSS疑难杂症
    DIV+CSS排版时 如何解决img图片元素下多余空白
    SQL备份相关的语句大全
    SQLServer2000同步复制技术实现步骤
  • 原文地址:https://www.cnblogs.com/wlw-x/p/12489230.html
Copyright © 2020-2023  润新知