2020训练赛6
B:
题意:给定n的,给定一些气球序列,判断有多少种不同的。
气球的种类个数是判断的标准。
如:132和3312,都有1,2,3这三个数,所以是同一类。
42和24424,都有2和4,所以是同一类
做法:用map存出现过的,边输入便判断
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <algorithm>
#include <string>
using namespace std;
int n;
map <int ,bool> mp;
int ans;
bool vis[10];
int main(){
// freopen("1.out","w",stdout);
while(~scanf("%d",&n)){
mp.clear();
ans=0;
int a[20],cnt=0;
for (int i=1;i<=n;i++){
memset(vis,0,sizeof(vis));
memset(a,0,sizeof(a));
cnt=0;
int x;
scanf("%d",&x);
while(x){
int z=x % 10;
if(!vis[z]){
vis[z]=1;
a[++cnt]=z;
}
x/=10;
}
sort(a+1,a+1+cnt);
int num=0;
for (int j=1;j<=cnt;j++){
num=num*10+a[j];
}
// cout<<"num"<<num<<endl;
if(mp[num]==false){
ans++;
mp[num]=true;
}
}
printf("%d\n",ans);
}
return 0;
}
C题
题意:给定一个原始字符串序列,通过给出的变换规则求出新的一个字符串
做法:遍历字符串,依次对原字符串进行替换。有一点要注意的是,当出现"//“这样的子串的时候替换为一个空格” "
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
string s;
string mp[26]={".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--",
"-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};
int main(){
while(cin>>s){
string sub="";
string ans="";
int cnt=0,pre=0;
for (int i=0;i<s.length();i++){
if(s[i]=='/'){
if(pre==1){
ans+=" ";
continue;
}
for (int i=0;i<26;i++){
if(mp[i]==sub){
ans+='A'+i;
}
}
sub="";
pre=1;
}
else{
sub+=s[i];
pre=0;
}
}
for (int i=0;i<26;i++){
if(mp[i]==sub){
ans+='A'+i;
}
}
cout<<ans<<endl;
}
return 0;
}
K题:
题意:给一个n*n的原始字母表,保证每一行、每一列的字母不会重复。问出错的位置是哪个,且原来的正确字母是哪个。
做法:
考虑两种情况:
1.出错的是原来和其他字母都不一样的
2.出错的是原来字母中的一个
先统计整个表中的每个字母的个数,如果发现有一个字母个数为1,则是第一种情况
第一种情况直接遍历整个表找出来出错的字母就行了,正确的字母就是数量为n-1的那个字母
第二种情况我们可以发现一定有一个字母的数量为n+1(出错的),一个为n-1(正确的)。先遍历整个字母表,记录每一行和每一列含有出错字母的个数。然后再遍历一遍每一行和每一列,若个数不为1,则表明出错的位置在这个地方
#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <map>
using namespace std;
const int maxn=110;
char mp[maxn][maxn];
int num[maxn];
int n;
int main(){
while(~scanf("%d",&n)){
int cnt=0;
memset(num,0,sizeof(num));
for (int i=0;i<n;i++){
scanf("%s",&mp[i]);
for (int j=0;j<n;j++){
num[mp[i][j]-'A']++;//统计每一种的个数
}
}
char a,b;
for (int i=0;i<26;i++){
if(num[i]==1) a='A'+i,cnt=1;//只有一个表示是原来没有的
else if(num[i]==n+1) a='A'+i;//一个多1
else if(num[i]==n-1) b='A'+i;//一个少1
}
if(cnt==1){
for (int i=0;i<n;i++){
for (int j=0;j<n;j++){
if(mp[i][j]==a){
printf("%d %d %c\n",i+1,j+1,b);
}
}
}
}
else{//原来有的
int c[maxn];
int r[maxn];
for (int i=0;i<=n;i++){
c[i]=r[i]=0;
}
for (int i=0;i<n;i++){
for (int j=0;j<n;j++){
if(mp[i][j]==a){
r[i]++;
c[j]++;
}
}
}
int ansr,ansc;
for (int i=0;i<n;i++){
if(r[i]!=1){
ansr=i;
}
if(c[i]!=1){
ansc=i;
}
}
printf("%d %d %c\n",ansr+1,ansc+1,b);
}
}
return 0;
}
J题:
题目大意:现在有若干个时间点Ti,每个时间点会获得一个价值为Vi。
给你若干个询问,求出在某个时间点之前L秒内满足要求的个数。
如:
lt min 300,表示对于每一个i (1<=i<=n) ,若v[i]小于区间[max(T[i]-300,0),T[i]) (左闭右开区间,同时保证最左区间非负)内所有价值的最小值,则答案+1.
gt avg 7200 ,表示对于每一个i (1<=i<=n) ,若v[i]大于区间[max(T[i]-7200,0),T[i]) (左闭右开区间,同时保证最左区间非负)内所有价值的平均值,则答案+1.
做法:时间是个递增序列,考虑用线段树维护价值的区间和、极值,然后从[2,n] 二分查找答案
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=1e5+10;
const int inf=0x3f3f3f3f;
int n,m;
int t[maxn],v[maxn];
int sum[maxn<<2],Min[maxn<<2],Max[maxn<<2];
void pushup(int rt){
sum[rt]=sum[rt<<1]+sum[rt<<1|1];
Min[rt]=min(Min[rt<<1],Min[rt<<1|1]);
Max[rt]=max(Max[rt<<1],Max[rt<<1|1]);
}
void build(int l,int r,int rt){
if(l==r){
scanf("%d%d",&t[l],&v[l]);
sum[rt]=Min[rt]=Max[rt]=v[l];
return ;
}
int m=(l+r)>>1;
build(l,m,rt<<1);
build(m+1,r,rt<<1|1);
pushup(rt);
}
int q_sum(int L,int R,int l,int r,int rt){
if(L<=l && r<=R){
return sum[rt];
}
int ans=0;
int m=(l+r)>>1;
if(L<=m) ans+=q_sum(L,R,l,m,rt<<1);
if(R>m) ans+=q_sum(L,R,m+1,r,rt<<1|1);
return ans;
}
int q_max(int L,int R,int l,int r,int rt){
if(L<=l && r<=R){
return Max[rt];
}
int ans=-inf;
int m=(l+r)>>1;
if(L<=m) ans=max(ans,q_max(L,R,l,m,rt<<1));
if(R>m) ans=max(ans,q_max(L,R,m+1,r,rt<<1|1));
return ans;
}
int q_min(int L,int R,int l,int r,int rt){
if(L<=l && r<=R){
return Min[rt];
}
int ans=inf;
int m=(l+r)>>1;
if(L<=m) ans=min(ans,q_min(L,R,l,m,rt<<1));
if(R>m) ans=min(ans,q_min(L,R,m+1,r,rt<<1|1));
return ans;
}
int main(){
while(~scanf("%d",&n)){
build(1,n,1);
scanf("%d",&m);
char s1[10],s2[10];
int x;
while(m--){
scanf("%s%s%d",s1,s2,&x);
int ans=0,l;
if(s2[0]=='a'){
for (int r=2;r<=n;r++){
int T=max(t[r]-x,0);//保证非负
l=lower_bound(t+1,t+n+1,T)-t;
if(l>r-1) continue;
if(s1[0]=='g'){
if(v[r]*(r-l)>q_sum(l,r-1,1,n,1)) ans++;
}
else {
if(v[r]*(r-l)<q_sum(l,r-1,1,n,1)) ans++;
}
}
}
else if(s2[1]=='i'){
for (int r=2;r<=n;r++){
int T=max(t[r]-x,0);//保证非负
l=lower_bound(t+1,t+n+1,T)-t;
if(l>r-1) continue;
if(s1[0]=='g'){
if(v[r]>q_min(l,r-1,1,n,1)) ans++;
}
else {
if(v[r]<q_min(l,r-1,1,n,1)) ans++;
}
}
}
else{
for (int r=2;r<=n;r++){
int T=max(t[r]-x,0);//保证非负
l=lower_bound(t+1,t+n+1,T)-t;
if(l>r-1) continue;
if(s1[0]=='g'){
if(v[r]>q_max(l,r-1,1,n,1)) ans++;
}
else {
if(v[r]<q_max(l,r-1,1,n,1)) ans++;
}
}
}
printf("%d\n",ans);
}
}
return 0;
}
E题:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
int b[8][2][2];
int n;
char st[105][105];
char ans[105][105];
string s;
int temp[2][2];
void add(int f[2][2],int p){
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
int x=b[p][i][j];
int t[2];
if(x==1){t[0]=0,t[1]=0;}
if(x==2){t[0]=0,t[1]=1;}
if(x==3){t[0]=1,t[1]=1;}
if(x==4){t[0]=1,t[1]=0;}
temp[i][j] = f[t[0]][t[1]];
}
}
}
int op2(char c){//一个操作,对应的是哪一种变换
if(c=='>')return 1;
if(c=='<')return 3;
if(c=='|')return 4;
if(c=='-')return 5;
if(c=='\\')return 6;
if(c=='/')return 7;
}
int x,y;
char change(char c,int d,int i,int j){//得到一个变化后的字符,和其在最终矩阵上的位置
if(d==0){//不变
x = i;y = j;
return c;
}
if(d==1){//顺时针90度
x = j;y = n-1-i;
if(c=='>') return 'v';
if(c=='<') return '^';
if(c=='v') return '<';
if(c=='^') return '>';
if(c=='|') return '-';
if(c=='-') return '|';
if(c=='/') return '\\';
if(c=='\\') return '/';
}
if(d==2){//旋转180度
x = n-1-i;y = n-1-j;
if(c=='>') return '<';
if(c=='<') return '>';
if(c=='v') return '^';
if(c=='^') return 'v';
if(c=='|') return '|';
if(c=='-') return '-';
if(c=='/') return c;
if(c=='\\') return c;
}
if(d==3){//逆时针旋转90度
y = i;x = n-1-j;
if(c=='>') return '^';
if(c=='<') return 'v';
if(c=='v') return '>';
if(c=='^') return '<';
if(c=='|') return '-';
if(c=='-') return '|';
if(c=='/') return '\\';
if(c=='\\') return '/';
}
if(d==4){//左右对称翻转
x = i;y = n-1-j;
if(c=='>') return '<';
if(c=='<') return '>';
if(c=='v') return 'v';
if(c=='^') return '^';
if(c=='|') return c;
if(c=='-') return c;
if(c=='/') return '\\';
if(c=='\\') return '/';
}
if(d==5){//上下对称翻转
x = n-1-i;y = j;
if(c=='>') return c;
if(c=='<') return c;
if(c=='v') return '^';
if(c=='^') return 'v';
if(c=='|') return c;
if(c=='-') return c;
if(c=='/') return '\\';
if(c=='\\') return '/';
}
if(d==6){//主对角线
x = j;y = i;
if(c=='>') return 'v';
if(c=='<') return '^';
if(c=='v') return '>';
if(c=='^') return '<';
if(c=='|') return '-';
if(c=='-') return '|';
if(c=='/') return c;
if(c=='\\') return c;
}
if(d==7){//副对角线
x = n-1-j;y = n-1-i;
if(c=='>') return '^';
if(c=='<') return 'v';
if(c=='v') return '<';
if(c=='^') return '>';
if(c=='|') return '-';
if(c=='-') return '|';
if(c=='/') return c;
if(c=='\\') return c;
}
if(c=='x'||c=='o'){//两种特殊的
return c;
}
}
void init(){//8种状态
b[0][0][0]=1;
b[0][0][1]=2;
b[0][1][1]=3;
b[0][1][0]=4;
b[1][0][0]=4;
b[1][0][1]=1;
b[1][1][1]=2;
b[1][1][0]=3;
b[2][0][0]=3;
b[2][0][1]=4;
b[2][1][1]=1;
b[2][1][0]=2;
b[3][0][0]=2;
b[3][0][1]=3;
b[3][1][1]=4;
b[3][1][0]=1;
b[4][0][0]=2;
b[4][0][1]=1;
b[4][1][1]=4;
b[4][1][0]=3;
b[5][0][0]=4;
b[5][0][1]=3;
b[5][1][1]=2;
b[5][1][0]=1;
b[6][0][0]=1;
b[6][0][1]=4;
b[6][1][1]=3;
b[6][1][0]=2;
b[7][0][0]=3;
b[7][0][1]=2;
b[7][1][1]=1;
b[7][1][0]=4;
}
int get(int temp[2][2]){
for(int i=0;i<8;i++){
bool flag=1;
for(int j=0;j<2;j++){
for(int k=0;k<2;k++){
if(b[i][j][k]!=temp[j][k]) flag=0;
}
}
if(flag) return i;
}
}
int main(){
// freopen("1.out","w",stdout);
init();
while(~scanf("%d",&n)){
for(int i=0;i<n;i++){
cin>>st[i];
getchar();
}
getline(cin,s);
int len=s.length();
int f[2][2];
f[0][0]=1;
f[0][1]=2;
f[1][1]=3;
f[1][0]=4;
for(int i=0;i<len;i+=2){//根据操作序列对正方形变换群进行操作
add(f,op2(s[i]));
for(int l=0;l<2;l++){
for(int r=0;r<2;r++){
f[l][r]=temp[l][r];//每做一次操作得到一个新的正方形
}
}
}
//做完之后f就是最后的状态了,在运用到原来的矩阵上
int res=get(f);//将状态转换为一个数0~7
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
x=i,y=j;
char tmp=change(st[i][j],res,i,j);
ans[x][y]=tmp;
}
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cout<<ans[i][j];
}
printf("\n");
}
}
return 0;
}