A. 小红平分糖果(签到)
// Problem: 小红平分糖果
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/82394/A
// Memory Limit: 524288 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
typedef long long ll;
typedef double db;
typedef pair<ll,int> P;
#define fi first
#define se second
#define pb push_back
#define dbg(x) cerr<<(#x)<<":"<<x<<" ";
#define dbg2(x) cerr<<(#x)<<":"<<x<<endl;
#define SZ(a) (int)(a.size())
#define sci(a) scanf("%d",&(a))
#define scll(a) scanf("%lld",&(a))
#define pt(a) printf("%d",a);
#define pte(a) printf("%d\n",a)
#define ptlle(a) printf("%lld\n",a)
#define debug(...) fprintf(stderr, __VA_ARGS__)
int v;
int main(){
sci(v);
if(v&1)puts("-1");
else printf("%d %d\n",v/2,v/2);
return 0;
}
B. 小红的完全平方数(枚举)
// Problem: 小红平分糖果
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/82394/A
// Memory Limit: 524288 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
typedef long long ll;
typedef double db;
typedef pair<ll,int> P;
#define fi first
#define se second
#define pb push_back
#define dbg(x) cerr<<(#x)<<":"<<x<<" ";
#define dbg2(x) cerr<<(#x)<<":"<<x<<endl;
#define SZ(a) (int)(a.size())
#define sci(a) scanf("%d",&(a))
#define scll(a) scanf("%lld",&(a))
#define pt(a) printf("%d",a);
#define pte(a) printf("%d\n",a)
#define ptlle(a) printf("%lld\n",a)
#define debug(...) fprintf(stderr, __VA_ARGS__)
const int M=1e6+100;
ll v;
ll ans=1e18;
int main(){
scanf("%lld",&v);
rep(i,1,M){
ll x=1ll*i*i;
if((v-x)%2==0){
ans=min(ans,abs(v-x)/2);
}
}
ptlle(ans);
return 0;
}
C. 小苯的字符串变化(枚举)
// Problem: 小苯的字符串变化
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/82394/C
// Memory Limit: 524288 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
typedef long long ll;
typedef double db;
typedef pair<ll,int> P;
#define fi first
#define se second
#define pb push_back
#define dbg(x) cerr<<(#x)<<":"<<x<<" ";
#define dbg2(x) cerr<<(#x)<<":"<<x<<endl;
#define SZ(a) (int)(a.size())
#define sci(a) scanf("%d",&(a))
#define scll(a) scanf("%lld",&(a))
#define pt(a) printf("%d",a);
#define pte(a) printf("%d\n",a)
#define ptlle(a) printf("%lld\n",a)
#define debug(...) fprintf(stderr, __VA_ARGS__)
const int N=1e5+100;
char s[N];
int n,cnt,a[N],res,ans=N;
int main(){
scanf("%s",s+1);
n=strlen(s+1);
rep(i,1,n){
a[i]=a[i-1];
if('A'<=s[i] && s[i]<='Z')continue;
a[i]++;
}
per(i,n,2){
if('a'<=s[i] && s[i]<='z'){
}
else{
res++;
}
ans=min(ans,a[i-1]+res);
}
pte(ans);
return 0;
}
D. 小红的子数组排列判断(尺取)
// Problem: 小苯的字符串变化
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/82394/C
// Memory Limit: 524288 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
typedef long long ll;
typedef double db;
typedef pair<ll,int> P;
#define fi first
#define se second
#define pb push_back
#define dbg(x) cerr<<(#x)<<":"<<x<<" ";
#define dbg2(x) cerr<<(#x)<<":"<<x<<endl;
#define SZ(a) (int)(a.size())
#define sci(a) scanf("%d",&(a))
#define scll(a) scanf("%lld",&(a))
#define pt(a) printf("%d",a);
#define pte(a) printf("%d\n",a)
#define ptlle(a) printf("%lld\n",a)
#define debug(...) fprintf(stderr, __VA_ARGS__)
const int N=1e5+100;
int a[N],k,n,cnt[N],now,ans;
int main(){
sci(n),sci(k);
rep(i,1,n)sci(a[i]);
rep(i,1,k){
if(a[i]<=k){
cnt[a[i]]++;
if(cnt[a[i]]==1)now++;
}
}
ans=(now==k);
rep(i,k+1,n){
if(a[i-k]<=k){
cnt[a[i-k]]--;
if(cnt[a[i-k]]==0)now--;
}
if(a[i]<=k){
cnt[a[i]]++;
if(cnt[a[i]]==1)now++;
}
if(now==k)ans++;
}
pte(ans);
return 0;
}
E. 小红的平行四边形(枚举+叉积)
把向量长度方向均相同的放入同一个vector内,
找到同一个vector内最小的截距和最大的截距,
二者如果不共线的话,就可以用叉积更新最大答案
复杂度O(n^2logn),自己写的比较丑,补一下烟花的代码吧
/**
* Created by 5cm/s on 2024/05/19 19:10:49.
* 诸天神佛,佑我上分!
**/
#include <bits/stdc++.h>
using namespace std;
#define itr(it) begin(it), end(it)
#define endl '\n'
#define YES() void(cout << "YES\n")
#define NO() void(cout << "NO\n")
using i64 = int64_t;
using pii = pair<i64, i64>;
using ld = long double;
void elysia() {
int n;
cin >> n;
vector<pii> p(n);
for (auto &[x, y]: p) cin >> x >> y;
map<pii, vector<ld>> mp;
for (int i = 0; i < n; ++i) {
auto [x1, y1] = p[i];
for (int j = i + 1; j < n; ++j) {
auto [x2, y2] = p[j];
i64 dx = x1 - x2, dy = y1 - y2;
i64 a = dy, b = -dx;
if (a < 0) a = -a, b = -b;
else if (a == 0) b = abs(b);
assert(a * x1 + b * y1 == a * x2 + b * y2);
mp[{a, b}].emplace_back(a * x1 + b * y1);
}
}
i64 ans = -1;
for (auto &[vec, dd]: mp) {
auto [a, b] = vec;
i64 d1 = *min_element(itr(dd)), d2 = *max_element(itr(dd));
if (d1 != d2) {
ans = max(ans, d2 - d1);
}
}
if (ans < 0) {
cout << -1 << endl;
} else {
cout << ld(ans) << endl;
}
}
int main() {
#ifdef MEGURINE
freopen("../input.txt", "r", stdin);
freopen("../output.txt", "w", stdout);
clock_t start = clock();
#endif
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T = 1;
// cin >> T;
cout << fixed << setprecision(1);
while (T--) elysia();
#ifdef MEGURINE
clock_t end = clock();
cout << "\nRunning Time: " << (double) (end - start) / CLOCKS_PER_SEC * 1000 << "ms" << endl;
#endif
return 0;
}
F. 小红小紫画线(容斥)
先选点,后连边涂颜色,这个题就好做了
先看下总共有4个点还是3个点,4个点交点在中间,3个点交点在端点
4个点有一条边上选4个(4)、一条边选3个另一条边选一个(3+1)、
一条边选2个另一条边选2个(2+2)、2+1+1、1+1+1+1这些情况
其中合法的有2+2、2+1+1、1+1+1+1,分别合法两种
3个点有2+1和1+1+1两种,2+1合法两种,1+1+1合法六种
分别统计即可,写的比较暴力,赛中还少写了一种情况导致没过
这里补一下NameError的写法
MOD = 10**9+7
n = int(input())
arr = list(map(int, input().split()))
s = sum(arr) % MOD
ans = s*(s-1)*(s-2)*(s-3)//12
ans -= sum(a*(a-1)*(a-2)//3 * (s-a) % MOD for a in arr)
ans -= sum(a*(a-1)*(a-2)*(a-3)//12 % MOD for a in arr)
ans += sum(a*(s-a)*(s-a-1) % MOD for a in arr)
print(ans % MOD)