A.无法用言语形容...一直被大佬搞,刚才从新读了遍题,是自己沙雕了
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//typedef __int128 bll;
const ll maxn = 1e5+100;
const ll mod = 1e9+7;
const ld pi = acos(-1.0);
const ll inf = 1e18;
const ld eps = 1e-5;
const ld e = exp(1);
ll n,t,ans,mi = inf;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin >> n >> t;
for(ll i = 1; i <= n; i++)
{
ll a,b;
cin >> a >> b;
if(t == a)
{
mi = -inf;
ans = i;
}
else if(t > a)
{
while(a < t)
{
a+=b;
}
if(a-t < mi)
{
mi = a-t;
ans = i;
}
}
else if(t < a)
{
if(a - t < mi)
{
mi = a-t;
ans = i;
}
}
}
cout << ans << endl;
return 0;
}
B.根据题意构造图形即可,因为输出任一合法的图形就OK,所以此题就很简单了
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//typedef __int128 bll;
const ll maxn = 1e2+100;
const ll mod = 1e9+7;
const ld pi = acos(-1.0);
const ll inf = 1e18;
const ld eps = 1e-5;
const ld e = exp(1);
ll n,m,h,a[maxn],ans[maxn][maxn],b[maxn];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin >> n >> m >> h;
for(ll i = 1; i <= m; i++)
{
cin >> a[i];
}
for(ll i = 1; i <= n; i++)
{
cin >> b[i];
}
for(ll i = 1; i <= n; i++)
{
for(ll j = 1; j <= m; j++)
{
ll x;
cin >> x;
if(x == 1)
{
ans[i][j] = min(b[i],a[j]);
}
else
{
ans[i][j] = 0;
}
}
}
for(ll i = 1; i <= n; i++)
{
for(ll j = 1; j <= m; j++)
{
cout << ans[i][j] << " ";
}
cout << endl;
}
return 0;
}
C。题意是要求你前缀非法,但是整个字符串要合法,也就是在左括号比右括号多的情况下构造即可(疯狂放左括号啊!)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//typedef __int128 bll;
const ll maxn = 3e5+100;
const ll mod = 1e9+7;
const ld pi = acos(-1.0);
const ll inf = 1e18;
const ld eps = 1e-5;
const ld e = exp(1);
ll len,l,r,sum;
char str[maxn];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin >> len;
cin >> str+1;
if(len%2 == 1)
{
cout << ":(" << endl;
}
else
{
ll l = 0,r = 0;
for(ll i = 1; i <= len; i++)
{
if(str[i] == '(')
l++;
else if(str[i] == ')')
r++;
}
ll k1 = len/2 - l,k2 = len/2 - r;
for(ll i = 1; i <= len; i++)
{
if(str[i] == '?')
{
if(k1)
{
k1--;
str[i] = '(';
}
else if(k2)
{
k2--;
str[i] = ')';
}
}
}
// for(ll i = 1; i <= len; i++)
// cout << str[i];
// cout << endl;
bool flag = true;
ll sum = 0;
for(ll i = 1; i <= len-1 && flag == true; i++)
{
if(str[i] == '(')
{
sum -= 1;
}
else
sum += 1;
if(sum >=0 )
flag = false;
}
if(flag && str[len] == ')')
{
for(ll i = 1; i <= len; i++)
cout << str[i];
cout << endl;
}
else
{
cout << ":(" << endl;
}
}
return 0;
}
D.树形DP...等候更新