CSP2017

2017-12-1 最小差值

#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int N = 1010;
int a[N];
int n;

int main()
{
    cin >> n;
    int mins = 1e9;
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++)
    {
        for(int j = i + 1; j < n; j++)
        {
            mins = min(mins, abs(a[j] - a[i]));
        }
    }
    cout << mins << endl;
}

2017-12-2 游戏

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
const int N = 1010;
int n, k;
bool st[N];

int main()
{
 	cin >> n >> k;
	if (n == 1)
	{
		cout << 1 << endl;
		return 0;
	}
	int size = n;
	int count = 0;
	for (int i = 1; i <= n + 1; i++)
	{
		if (i == n + 1)
			i = 1;
		if (!st[i])
		{
			count++;
			if (count % k == 0 || count % 10 == k)
			{
				st[i] = true;
				size--;
				if (size == 1)
					break;
			}
		}
	}
	for (int i = 1; i <= n; i++)
	{
		if (!st[i])
		{
			cout << i << endl;
			break;
		}
	}
	return 0;
}

2017-9-1

#include<iostream>
using namespace std;
int main()
{
	int x;
	cin >> x;
	int ans = 0;
	while (x > 0)
	{
		if (x >= 50)
		{
			ans += 7;
			x = x - 50;
		}
		else if (x >= 30)
		{
			ans += 4;
			x = x - 30;
		}
		else
		{
			ans += x / 10;
			x = 0;
		}
	}
	cout << ans;
	return 0;
}

2017-9-2

#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1010;
int n, k;
int classroom[N];
struct key
{
	int num;
	int status;
	int time;
	bool operator< (const key& t) const
	{
		if (time != t.time) return time < t.time;
		if (status != t.status) return status < t.status;
		return num < t.num;
	}
}a[N * 2];

int find(int num)
{
	for (int i = 1; i <= n; i++)
	{
		if (classroom[i] == num)
			return i;
	}
}

int main()
{
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		classroom[i] = i;
	int num, start, time;
	int cnt = 0;
	for (int i = 0; i < k; i++)
	{
		scanf("%d%d%d", &num, &start, &time);
		a[cnt++] = { num, 1, start };  //取
		a[cnt++] = { num, 0, start + time };  //放
	}
	sort(a, a + cnt);
	for (int i = 0; i < cnt; i++)
	{
		if (a[i].status == 1)
		{
			classroom[find(a[i].num)] = -1;
		}
		else
		{
			for (int j = 1; j <= n; j++)
			{
				if (classroom[j] == -1)
				{
					classroom[j] = a[i].num;
					break;
				}
			}
		}
	}
	for (int i = 1; i <= n; i++)
		if (i == 1) cout << classroom[i];
		else cout << " " << classroom[i];
	cout << endl;
}

2017-3-1

#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int N = 1010;
int n, k;
int a[N];

int main()
{
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	int sum = 0, res = 0;
	int i = 1;
	while (i <= n)
	{
		sum += a[i];
		if (sum >= k || i == n)
		{
			sum = 0;
			res++;
		}
		i++;
	}
	cout << res << endl;
}

2017-3-2

#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int n, k;
const int N = 1010;
int a[N];

int find(int x)
{
	for (int i = 1; i <= n; i++)
	{
		if (a[i] == x)
			return i;
	}
}

void move1(int x, int y)
{
	for (int i = x + 1; i <= x + y; i++)
	{
		swap(a[i], a[i - 1]);
	}
}

void move2(int x, int y)
{
	for (int i = x - 1; i >= x - y; i--)
	{
		swap(a[i], a[i + 1]);
	}
}

int main()
{
	cin >> n >> k;
	for (int i = 1; i <= n; i++) a[i] = i;
	int x, y;
	while (k--)
	{
		cin >> x >> y;
		if (y > 0)
			move1(find(x), y);
		else
			move2(find(x), -y);
		
	}
	for (int i = 1; i <= n; i++)
		if (i == 1) cout << a[i];
		else cout << " " << a[i];
	cout << endl;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值