Educational Codeforces Round 90 (Rated for Div. 2)
A
根据题意模拟一下即可
#include
#define sz(X) ((int)(X).size())
#define all(X) (X).begin(), (X).end()
#define rep(I, N) for (int I = 1; I <= (N); ++I)
#define repp(I, N) for (int I = 0; I < (N); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORR(I, A, B) for (int I = (A); I >= (B); I--)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define mp make_pair
#define pb push_back
#define ms0(X) memset((X), 0, sizeof((X)))
#define ms1(X) memset((X), -1, sizeof((X)))
#define len(X) strlen(X)
#define f first
#define s second
using namespace std;
const int N = 2e5 + 5;
const double eps = 1e-7;
const int mod = 1e9 + 7;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair pii;
typedef vector vi;
typedef vector vl;
typedef vector vpii;
typedef pair pll;
typedef vector vpll;
ll gcd(ll a,ll b){return b>0?gcd(b,a%b):a;}
ll ksm(ll a,ll b){ll ans = 1;while(b){if(b&1) ans = ans * a % mod;a = a * a % mod;b >>= 1;}return ans % mod;}
int a[N];
std::vector v1,v2;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while(t--)
{
ll a,b,c;
cin >> a >> b >> c;
int flag = 0;
if(a >= c)
{
cout << "-1" << ' ' << b <
B
比赛时候我 \(5min\) 过的 \(B\) ,就是找到 \(0\) 和 \(1\) 的个数,然后取个数较小的那一个,看一下个数模 \(2\) 的余数。
#include
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
string s;
while(t--)
{
cin >> s;
int ans1= 0 ,ans2= 0;
for(int i = 0;i < s.size();i++)
{
if(s[i] == '0') ans1++;
else ans2++;
}
if(ans1 > ans2) swap(ans1,ans2);
if(ans1 % 2 == 0)
{
cout << "NET" << endl;
}
else cout << "DA" << endl;
}
return 0;
}
C
丑到不行的代码
其实就是 \(+\) 看成 \(+1\) \(-\) 号看成 \(-1\) 。然后取前缀和,找到负数成下降的下标相加即可。
#include
#define sz(X) ((int)(X).size())
#define all(X) (X).begin(), (X).end()
#define rep(I, N) for (int I = 1; I <= (N); ++I)
#define repp(I, N) for (int I = 0; I < (N); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORR(I, A, B) for (int I = (A); I >= (B); I--)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define pb push_back
#define ms0(X) memset((X), 0, sizeof((X)))
#define ms1(X) memset((X), -1, sizeof((X)))
#define len(X) strlen(X)
#define f first
#define s second
using namespace std;
const int N = 1e6 + 5;
const double eps = 1e-7;
const int mod = 1e9 + 7;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair pii;
typedef vector vi;
typedef vector vl;
typedef vector vpii;
typedef pair pll;
typedef vector vpll;
ll gcd(ll a,ll b){return b>0?gcd(b,a%b):a;}
ll ksm(ll a,ll b){ll ans = 1;while(b){if(b&1) ans = ans * a % mod;a = a * a % mod;b >>= 1;}return ans % mod;}
char a[N];
ll sum[N];
map mp;
int main() {
int t;
scanf("%d",&t);
while(t--)
{
mp.clear();
scanf("%s",a + 1);
int n = strlen(a + 1);
for(int i = 1;i <= n;i++)
{
if(a[i] == '-')
sum[i] = sum[i - 1] - 1;
else sum[i] = sum[i - 1] + 1;
}
ll ans = 0;
int last = -1;
int cnt = 0;
for(int i = 1;i <= n;i++)
{
if(sum[i] < 0) {
ans = i;
break;
}
}
//cout << ans << endl;
for(int i= 1;i <= n;i++)
{
if(sum[i] >= 0) {
cnt ++;
continue;
}
else
{
if(sum[i] <= last)
{
last = sum[i];
mp[sum[i]] = i + 1;
if(i == n) mp[sum[i]] = i;
}
}
}
ll cnt1= 0;
for(auto it = mp.begin();it != mp.end();it++){
ans += it->second;
cnt1 = max(cnt1,it->second);
}
ans -= cnt1;
ans += n;
if(cnt == n) ans = n;
cout << ans << endl;
// int res = 0;
// for(int i = 0;i <= 100000;i++)
// {
// int cur = i;
// int ok = 1;
// for(int j = 1;j <= n;j++)
// {
// res += 1;
// if(a[j] == '+') cur += 1;
// else cur -= 1;
// if(cur < 0)
// {
// ok = 0;
// break;
// }
// }
// //cout << res << endl;
// if(ok) break;
// }
// cout << res << endl;
}
return 0;
}
D
这题有点东西。
发现翻转其实就是对应的\(1、2,3、4\)相交换。
#include
#define sz(X) ((int)(X).size())
#define all(X) (X).begin(), (X).end()
#define rep(I, N) for (int I = 1; I <= (N); ++I)
#define repp(I, N) for (int I = 0; I < (N); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORR(I, A, B) for (int I = (A); I >= (B); I--)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define pb push_back
#define ms0(X) memset((X), 0, sizeof((X)))
#define ms1(X) memset((X), -1, sizeof((X)))
#define len(X) strlen(X)
#define f first
#define s second
using namespace std;
const int N = 2e5 + 5;
const double eps = 1e-7;
const int mod = 1e9 + 7;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair pii;
typedef vector vi;
typedef vector vl;
typedef vector vpii;
typedef pair pll;
typedef vector vpll;
ll gcd(ll a,ll b){return b>0?gcd(b,a%b):a;}
ll ksm(ll a,ll b){ll ans = 1;while(b){if(b&1) ans = ans * a % mod;a = a * a % mod;b >>= 1;}return ans % mod;}
//int a[N];
//std::vector v1,v2;
int a[N];
ll sum1[N],sum2[N];
int x[N],y[N];
ll xx[N];
map mp;
ll MaxSum(int n,ll *a)
{
ll sum=0,b=0;
for(int i=1;i<=n;i++)
{
if(b<0) b+=a[i];
else b=a[i];
if(b<=sum)
sum=b;
}
for(int i =1;i <= n;i++)
{
sum = min(sum,a[i]);
}
return sum;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
//int t;
//scanf("%d",&t);
int t;
cin >> t;
while(t--)
{
int tota = 0,totb = 0;
int n;
cin >> n;
for(int i = 1;i <= n;i++)
{
sum1[i] = 0;
sum2[i] = 0;
xx[i] = 0;
}
rep(i,n) cin >> a[i];
for(int i = 1;i <= n;i+=2)
{
x[++tota] = a[i];
}
for(int i = 2;i <= n;i+=2)
y[++totb] = a[i];
ll ans = 0;
int tt = 0;
for(int i = 1;i <= tota;i++) ans += x[i];
for(int i = 1;i <= min(tota,totb);i++)
{
xx[++tt] = x[i] - y[i];
}
ll cnt1 = MaxSum(tota,xx);
for(int i = 1;i <= tt;i++) xx[i] = 0;
tt = 0;
for(int i = 2;i <= tota;i++)
{
xx[++tt] = x[i] - y[i - 1];
}
ll cnt2 = MaxSum(tota,xx);
ans += max(abs(cnt1),abs(cnt2));
cout << ans << endl;
}
return 0;
}