@darkproject
2016-12-08T21:27:46.000000Z
字数 1963
阅读 904
作业
A Design Tutorial: Learn from Math
本来打算合数筛选判断的,后来猜了下居然A啦qwq
#include<iostream>
using namespace std;
int main()
{
int n, x, y;
cin >> n;
if (n % 2 == 0) cout << "4 " << n - 4 << endl;
else cout << "9 " << n - 9 << endl;
return 0;
}
B Design Tutorial: Learn from Life
贪心,排序后从高处开始,每次拉k人,遇到需要停下的人就把他们放下,然后继续运输
#include<iostream>
#include<algorithm>
using namespace std;
int a[2005];
int main()
{
int n, k, ans = 0;
cin >> n >> k;
for (int i = 1; i <= n; ++i) cin >> a[i];
sort(a+1,a + n+1);
for (int i = n; i > 0; i -= k)
ans += 2 * a[i] - 2;
cout << ans << endl;
return 0;
}
C Design Tutorial: Make It Nondeterministic
给出一个人的两个名字,选择其中一个,让所有人名序列满足字典序,
第一个输入数据取最短,然后与第二个数据最短比较,不符与第二个数据最长比较,还不符就GG,符合继续比较第三个。
#include<bits/stdc++.h>
using namespace std;
struct {
string f;
string l;
}str[100005];
int num[100005];
bool flag = true;
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; ++i) cin >> str[i].f>>str[i].l;
for (int i = 1; i <= n; ++i) cin >> num[i];
string now = min(str[num[1]].f, str[num[1]].l);
for (int i = 2; i <= n; ++i)
{
string temp = min(str[num[i]].f, str[num[i]].l);
if (now >= temp)
{
temp = max(str[num[i]].f, str[num[i]].l);
if (now >= temp)
{
flag = false;
break;
}
now = temp;
}
else now = temp;
}
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
F MUH and Important Things
n个任务,每个任务有难度值,在保证难度值优先最小的情况下,得到序列是否有3.排序然后遇到相当难度值考虑多情况交换
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
struct arr{
int number;
int value;
}data1[2005];
bool cmp(const arr &a, const arr &b)
{
return a.value < b.value;
}
int main()
{
int n, num = 0;
cin >> n;
for (int i = 1; i <= n; ++i)
{
cin >> data1[i].value;
data1[i].number = i;
}
sort(data1 + 1, data1 + n + 1, cmp);
for (int i = 1; i <= n - 1; ++i)
if (data1[i].value == data1[i + 1].value) num++;
if (num<2) {
cout << "NO" << endl;
return 0;
}
else
{
cout << "YES" << endl;
for (int t = 0; t < 3; t++)
{
for (int i = 1; i <= n; i++)
printf("%d ", data1[i].number);
printf("\n");
for (int i = 1; i < n; i++)
{
if (data1[i].value == data1[i + 1].value && data1[i].number < data1[i + 1].number)
{
swap(data1[i], data1[i + 1]);
break;
}
}
}
}
return 0;
}
I - George and Accommodation
qwq
#include<iostream>
#include<cstdio>
using namespace std;
int n,m;
int main()
{
scanf("%d",&n);
int x,y;
for(int i=1;i<=n;i++)
{
scanf("%d%d",&x,&y);
if(y-x>=2)
m++;
}
printf("%d",m);
return 0;
}