终于考完了,可以愉快的整一整了,大概。摸了(
A. Finding Sasuke
给定长为n个数字的数列{an},n为偶数,求{bn}令a1×b1+a2×b2+......=0,|an|小于100,要求|bn|也小于100
令每两个的an×bn为0即可
#include<iostream>
#include<queue>
#include<map>
#include<utility>
#include<vector>
#include<algorithm>
#include<cstring>
#include<string>
#include<stdio.h>
#include<sstream>
#include<fstream>
#include<cmath>
#include<set>
#include<math.h>
using namespace std;
typedef long long ll; //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
ll vis[100000 + 5];
ll dat[100000 + 5];
ll val[100001 << 2];
ll lst[100000 + 5];
ll n;
const int M = 5000000 ;
int main() {
ll t;
cin >> t;
while (t--)
{
cin >> n;
for (int i = 0; i < n; i++)
cin >> dat[i];
for (int i = 0; i < n; i += 2) {
cout << dat[i + 1] << ' ' << -1 * dat[i] << ' ';
}
cout << '
';
}
}
B. A New Technique
给定一个n*m的表格,内部元素全不相同 给出每行和每列,求原表格
行已知,就只要查找哪个是第一列即可,按第一列输出即可。
#include<iostream>
#include<queue>
#include<map>
#include<utility>
#include<vector>
#include<algorithm>
#include<cstring>
#include<string>
#include<stdio.h>
#include<sstream>
#include<fstream>
#include<cmath>
#include<set>
#include<math.h>
using namespace std;
typedef long long ll; //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
bool vis[1000000 + 5];
ll mapp[600][600];
ll pos[250000 + 5];
ll m;
ll n;
const int M = 5000000 ;
int main() {
ll t;
cin >> t;
while (t--)
{
cin >> n >> m;
memset(vis, 0, n * m + 1);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
cin >> mapp[i][j];
if (j == 0) {
vis[mapp[i][j]] = 1;
pos[mapp[i][j]] = i;
}
}
ll flag = 0;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
ll tmp;
cin >> tmp;
if (j == 0 && vis[tmp] == 1) {
flag = 1;
}
if (flag) {
for (int k = 0; k < m; k++)cout << mapp[pos[tmp]][k] << ' ';
cout << '
';
}
if (j == n - 1)flag = 0;
}
}
}
}
C. Perform Easily
给定六根弦的初始音高,再给定目标音高,则要弹响目标音高,需要按下的品位为目标音高减去弦的初始音高。给定谱子,可以自由安排每个音在哪根弦上弹响,求最高品位与最低品位之差的最小值。
先把弦的音高排序,每个都减去最小的音高,则最低品位为最大值,都放进一个set里面。然后每次取set里的最大值,让他用更高音的弦。这样我们就能在固定最小值的情况下,遍历最大值。每次更新ans即可。具体实现可以用pair储存品位和音高的编号。
#include <iostream>
#include <cstring>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
set<P> a;
ll st[6];
ll n;
ll dat[100000 + 5];
ll dat2[100000 + 5];
int main() {
for (int i = 0; i < 6; i++)cin >> st[i];
sort(st, st + 6);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> dat[i];
a.insert(P(dat[i] - st[0], i));
}
P tmp;
ll minn = 1000000000000000;
while (1) {
tmp = *a.rbegin();
if (dat2[tmp.second] == 5)break;
else {
int ti = tmp.second;
dat2[ti]++;
P tmp2 = P(dat[ti] - st[ dat2[ti]], ti);
a.erase(*a.rbegin());
a.insert (tmp2);
minn = min(ll((*a.rbegin()).first - (*a.begin()).first), minn);
}
}
cout << minn;
}
D. Shurikens
一共有价格为1到n的商品,给定2n个输入,若输入为 + ,则说明给商店上架新商品,若为 - i,则说明价格为i的商品被卖出。且每次卖出都只能卖出当前上架了的商品中价格最小的那个。问能否实现,以及该以何种顺序上架商品。
可以从后往前考虑,用set存当前还剩下啥商品,如果i卖出了,说明当前最小的商品就为i,把它加入到一个set中。如果卖出的i比剩下的最小值大了,或者当前根本没有商品,都是不符合情况的。遇到+,则认为当前最便宜的商品是此时上架,把最小值删掉,加到ans数组里去即可。
#include <iostream>
#include <cstring>
#include <stdio.h>
#include <algorithm>
#include <set>
#include<vector>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
ll n, t;
set<ll> a;
vector<ll>ans;
ll datt[500000 + 5];
int main() {
ios::sync_with_stdio(false);
cin >> n;
for (int i = 0; i < 2 * n; i++) {
char tmp;
cin >> tmp;
if (tmp == '+') {
datt[i] = 0;
continue;
}
else {
ll b;
cin >> b;
datt[i] = b;
}
}
for (int i = 2 * n - 1; i >= 0; i--) {
if (datt[i] == 0) {
if (a.empty()) {
cout << "NO";
return 0;
}
else {
ans.push_back(*a.begin());
a.erase(*a.begin());
}
}
else {
if ((!a.empty())&&datt[i] > * a.begin()) {
cout << "NO";
return 0;
}
else {
a.insert(datt[i]);
}
}
}
cout << "YES
";
for (int i = ans.size() - 1; i >= 0; i--)cout << ans[i] << ' ';
}