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;
    }
    
  • 相关阅读:
    给python脚本传递命令行参数
    python.exe和pythonw.exe的区别(区分.py、.pyw、.pyc文件)
    python包管理器pip
    python从新手到安装指南
    python基础知识
    使用Lua做为MMOARPG游戏逻辑开发脚本的一点体会
    游戏中各音效的音量默认值
    Unity Editor自定义菜单排序(MenuItem Order)
    没有安装vs通过Rider编译Dll
    MyBatis-Plus 代码生成器
  • 原文地址:https://www.cnblogs.com/wlw-x/p/12489230.html
Copyright © 2011-2022 走看看