hey_left 17 Codeforces Round 817 (Div. 4)
A.
把标准字符串和输入字符串排序,看是否相等
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+10;
void solve(){
int n;cin>>n;
string t;cin>>t;
string s="Timur";
sort(s.begin(),s.end());
sort(t.begin(),t.end());
if(s==t)cout<<"YES"<<'\n';
else cout<<"NO"<<'\n';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int hey_left=1;
cin>>hey_left;
while(hey_left--){
solve();
}
}
C.
因为每个人的n个是不同的,所以若一个字符串出现了多次,那么一定是多个人写的
可以记录下每个字符串是哪些人写的,根据人数计分
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+10;
void solve(){
int n;cin>>n;
map<string,vector<int>>mp;
string t;
for(int i=1;i<=3;i++)
for(int j=1;j<=n;j++){
cin>>t;
mp[t].push_back(i);
}
int s1=0,s2=0,s3=0;
for(auto tmp:mp){
if(tmp.second.size()==1){
int id=tmp.second[0];
if(id==1)s1+=3;
else if(id==2)s2+=3;
else if(id==3)s3+=3;
}else if(tmp.second.size()==2){
// cout<<tmp.first<<'\n';
int id=tmp.second[0],index=tmp.second[1];
if(id==1||index==1)s1+=1;
if(id==2||index==2)s2+=1;
if(id==3||index==3)s3+=1;
}
}
cout<<s1<<' '<<s2<<' '<<s3<<' '<<'\n';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int hey_left=1;
cin>>hey_left;
while(hey_left--){
solve();
}
}
D.
本来的贡献可以计算出来
每个位置若能改变方向,增加的贡献预处理出来
降序排序,再求前缀和
可以改变几个方向,就加上这个前缀和
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+10;
bool cmp(int x,int y){
return x>y;
}
void solve(){
int n;cin>>n;
string s;cin>>s;
vector<int>v(n),pre(n);
int sum=0;
for(int i=0;i<s.size();i++){
v[i]=max(i-0,n-1-i);
if(s[i]=='L')v[i]-=i-0;
else if(s[i]=='R')v[i]-=n-1-i;
if(s[i]=='L')sum+=i-0;
else if(s[i]=='R')sum+=n-i-1;
}
sort(v.begin(),v.end(),cmp);
for(int i=0;i<n;i++){
if(i==0)pre[i]=v[i];
else pre[i]=pre[i-1]+v[i];
}
for(int i=1;i<=n;i++){
cout<<sum+pre[i-1]<<' ';
}
cout<<'\n';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int hey_left=1;
cin>>hey_left;
while(hey_left--){
solve();
}
}
E.
太强了,二维前缀和
平面直角坐标,天然的度量
O(1)找任意边长
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1e9+7;
const int INF=0x3f3f3f3f;
const int N = 1e5+10;
#define ios ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
int sum[1050][1050];
void solve()
{
memset(sum,0,sizeof(sum));
int n,q;
cin>>n>>q;
for(int i=1;i<=n;i++)
{
int h,w;
cin>>h>>w;
sum[h][w]+=h*w;
}
n = 1e3;
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= n; j ++)
sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
for(int i=1;i<=q;i++)
{
int h1,w1,h2,w2;
cin>>h1>>w1>>h2>>w2;
ll res=sum[h2-1][w2-1]-sum[h2-1][w1]-sum[h1][w2-1]+sum[h1][w1];
cout<<res<<"\n";
}
}
signed main()
{
int t;
cin>>t;
while(t--)
{
solve();
}
}
F.
dfs找连通块,若连通块大小大于3,标记,跳过
若等于3,因为我们按从上到下,从左到右搜的,所以4种情况我们最先搜到的那一个是已知的,判4种情况若有一种成立就可以
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef priority_queue<int, vector<int>, less<int>> Q;
#define x first
#define y second
#define endl '\n'
#define ppb pop_back
#define pb push_back
#define pf push_front
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mset(x, a) memset(x, a, sizeof(x))
#define rep(i, l, r) for (LL i = l; i <= (r); ++i)
#define per(i, r, l) for (LL i = r; i >= (l); --i)
const int N = 1e2 + 10, inf = 0x3f3f3f3f, mod = 998244353;
int n, m;
char g[100][100];
int b[N][N]; // 记录每个*有没有被判断过
bool check(int x, int y)
{
int sum = 0;
for (int i = -1; i <= 1; i++)
for (int j = -1; j <= 1; j++)
if (g[x + i][y + j] == '*')
sum++;
return sum == 3;
}
bool get(int x, int y)
{
b[x][y] = 1;
int sum = 1;
if (g[x + 1][y - 1] == '*')
{
b[x + 1][y - 1] = 1;
sum++;
}
if (g[x + 1][y] == '*')
{
b[x + 1][y] = 1;
sum++;
}
if (g[x][y + 1] == '*')
{
b[x][y + 1] = 1;
sum++;
}
if (g[x + 1][y + 1] == '*')
{
b[x + 1][y + 1] = 1;
sum++;
}
return sum == 3;
}
void solve()
{
int ok = 1;
mset(g, 'a');
mset(b, 0);
cin >> n >> m;
for (int i = 1; i <= n; i++)
scanf("%s", g[i] + 1);
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
if (g[i][j] == '*' && b[i][j] == 0)
{
if (!get(i, j))
ok = 0;
}
if (g[i][j] == '*')
{
if (!check(i, j))
ok = 0;
}
}
}
if (ok)
YES;
else
NO;
}
signed main()
{
#ifdef Xin
freopen("in.in", "r", stdin);
freopen("out.out", "w", stdout);
#endif
int T = 1;
cin >> T;
while (T--)
solve();
return 0;
}
G.
即让所有数异或和为0
前n-3填1到n-3,第n-2和n-1随便填两个大数
在记录下奇数位的异或和与偶数位的异或和,第n个数就是两个数的异或
#include<bits/stdc++.h>
using namespace std;
int T,n,a[200005],v1,v2;
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>T;
for(;T--;){
v1=0,v2=0;
cin>>n;
for(int i=1;i<=n-3;i++){
a[i]=i;
if(i&1)v1^=i;
else v2^=i;
}
a[n-2]=998244353;
a[n-1]=1000000007;
if((n-2)&1)v1^=a[n-2];
else v2^=a[n-2];
if((n-1)&1)v1^=a[n-1];
else v2^=a[n-1];
a[n]=v1^v2;
for(int i=1;i<=n;i++)cout<<a[i]<<" ";
cout<<"\n";
}
return 0;
}