全部评论
第4题 #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i)
#define MP make_pair
#define fi first
#define se second
typedef long long LL;
const int N = 2e5 + 100;
int T;
int a[N], b[N], aa[N];
int c[N];
int cnt;
int n;
int mx, my;
LL ans = 0;
vector <int> v[N];
inline int query(int x){
if (x <= 0) return 0;
int ret = 0;
for (; x; x -= x & -x) ret += c[x];
return ret;
}
inline void update(int x){
for (; x <= 2e5; x += x & -x) ++c[x];
}
void ins(int x){
int tmp = query(x) - query(x - 1);
if (tmp) return;
update(x);
}
int main(){
scanf("%d", &T);
while (T--){
ans = 0;
cnt = 0;
scanf("%d", &n);
rep(i, 1, n){
scanf("%d%d", a + i, b + i);
aa[++cnt] = a[i];
aa[++cnt] = b[i];
}
memset(c, 0, sizeof c);
sort(aa + 1, aa + cnt + 1);
cnt = unique(aa + 1, aa + cnt + 1) - aa - 1;
rep(i, 1, n) a[i] = lower_bound(aa + 1, aa + cnt + 1, a[i]) - aa;
rep(i, 1, n) b[i] = lower_bound(aa + 1, aa + cnt + 1, b[i]) - aa;
mx = my = 0;
rep(i, 1, 2e5) v[i].clear();
rep(i, 1, n) v[a[i]].push_back(b[i]), mx = max(mx, a[i]), my = max(my, b[i]);
dec(i, mx, 1){
int mm = 0;
for (auto u : v[i]) ins(u), mm = max(mm, u);
ans += 1ll * query(mm);
}
printf("%lld\n", ans);
}
return 0;
}
第一题a了 其它的不是我等平民能做的
开始做的时候已经差不多快9点了……第3题大模拟有点搞不清楚他的优先级怎么设定的然后代码量估计很大就弃了最后只能100 100 0 100
第一题求帮忙看下哪里的问题 #include <stdio.h> #include <stdlib.h> int main(){ int i,j,k; int first,second,third; int n = 0; int spilit[1000][2][3]={0}; int count[1000][9]={0}; int sum[9]={0}; int big; int reg1,reg2,reg3,reg4,reg5,reg10; //个十百千万位寄存器 int reg6,reg7,reg8,reg9; //十百千万进位寄存器 scanf("%d",&i); for(n = 0; n < i; n++){ int x1,x2; scanf("%d %d",&x1,&x2); spilit[n][0][0]=x1/100; //百位 spilit[n][0][1]=x1/10-x1/100*10; //十位 spilit[n][0][2]=x1-x1/10*10; //个位 spilit[n][1][0]=x2/100; //百位 spilit[n][1][1]=x2/10-x2/100*10; //十位 spilit[n][1][2]=x2-x2/10*10; //个位 if(spilit[n][0][0]!=0) count[n][spilit[n][0][0]-1]++; if(spilit[n][0][1]!=0) count[n][spilit[n][0][1]-1]++; if(spilit[n][0][2]!=0) count[n][spilit[n][2][0]-1]++; if(spilit[n][1][0]!=0) count[n][spilit[n][1][0]-1]++; if(spilit[n][1][1]!=0) count[n][spilit[n][1][1]-1]++; if(spilit[n][1][2]!=0) count[n][spilit[n][1][2]-1]++; reg1=(spilit[n][0][2]*spilit[n][1][2])-(spilit[n][0][2]*spilit[n][1][2])/10*10; //个位 if(reg1!=0) count[n][reg1-1]++; reg6=spilit[n][0][2]*spilit[n][1][2]/10; //进到十位 first=spilit[n][0][2]*spilit[n][1][1]-spilit[n][0][2]*spilit[n][1][1]/10*10; second=spilit[n][0][1]*spilit[n][1][2]-spilit[n][0][1]*spilit[n][1][2]/10*10+reg6; reg2=first+second-(first+second)/10*10; reg7=(first+second)/10; if(first!=0) count[n][first-1]++; if(second!=0) count[n][second-1]++; if(reg2!=0) count[n][reg2-1]++; first=spilit[n][0][2]*spilit[n][1][0]-spilit[n][0][2]*spilit[n][1][0]/10*10; second=spilit[n][0][1]*spilit[n][1][1]-spilit[n][0][1]*spilit[n][1][1]/10*10; third=spilit[n][0][0]*spilit[n][1][2]-spilit[n][0][0]*spilit[n][1][2]/10*10+reg7; reg3=first+second+third-(first+second+third)/10*10; reg8=(first+second+third)/10; if(first!=0) count[n][first-1]++; if(second!=0) count[n][second-1]++; if(third!=0) count[n][third-1]++; if(reg3!=0) count[n][reg3-1]++; first=spilit[n][0][0]*spilit[n][1][1]-(spilit[n][0][0]*spilit[n][1][1])/10*10+reg8; second=spilit[n][0][1]*spilit[n][1][0]-(spilit[n][0][1]*spilit[n][1][0])/10*10; reg4=first+second-(first+second)/10*10; //qianwei reg9=(first+second)/10; if(first!=0) count[n][first-1]++; if(second!=0) count[n][second-1]++; if(reg4!=0) count[n][reg4-1]++; first=spilit[n][0][0]*spilit[n][1][0]-spilit[n][0][0]*spilit[n][1][1]/10*10+reg9; reg5=first-(first)/10*10; if(first!=0) count[n][first-1]++; if(reg5!=0) count[n][reg5-1]++; reg10=spilit[n][0][0]*spilit[n][1][0]/10; if(reg10!=0) count[n][reg10-1]++; } for(n=0;n<i;n++){ for(j=0;j<9;j++){ sum[count[n][j]]++; } printf("%d ",sum[n]); printf("\n"); } big=sum[0]; for(n=0;n<i;n++){ if(sum[n]>big) big=sum[n]; } printf("%d",big); return 0; }
package wangyi;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.concurrent.ConcurrentHashMap;
public class Main1 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
if(n==0){
return;
}
int input[][]=new int[n][2];
for(int i=0;i<n;i++){
input[i][0]=sc.nextInt();
input[i][1]=sc.nextInt();
}
List<List<Integer>> list=new ArrayList<>();
for(int i=0;i<n;i++){
List<Integer>ans=new ArrayList<>();
List<Integer>temp=new ArrayList<>();
for(int q=0;q<11;q++){
ans.add(0);
}
temp.add(input[i][0]);
temp.add(input[i][1]);
String str=input[i][1]+"";
for(int j=0;j<str.length();j++){
temp.add((str.charAt(j)-'0')*input[i][0]);
}
temp.add(input[i][0]*input[i][1]);
int max=Integer.MAX_VALUE;
for(int j=0;j<temp.size();j++){
String str1=temp.get(j)+"";
for(int k=0;k<str1.length();k++){
int pos=str1.charAt(k)-'0';
ans.set(pos,ans.get(pos)+1);
if(ans.get(pos)+1>max&&pos!=0){
max=ans.get(pos)+1;
ans.set(10,pos);
}
}
}
list.add(ans);
}
List<Integer>zzAns=new ArrayList<>();
for(int i=0;i<9;i++){
zzAns.add(0);
}
int maxPos=0;
int maxVal=Integer.MIN_VALUE;
for(List<Integer>iter:list){
for(int i=1;i<10;i++){
zzAns.set(i-1,zzAns.get(i-1)+iter.get(i));
System.out.print(iter.get(i)+" ");
if(zzAns.get(i-1)+iter.get(i)>maxVal){
maxPos=i;
maxVal=zzAns.get(i-1)+iter.get(i);
}
}
System.out.println();
}
System.out.println(maxPos);
}
}
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<vector>
#include<queue>
using namespace std;
typedef long long LL;
struct node{
int c;
int tn;
int tm;
int num;
node(int a,int b,int dd,int d)
{
c = a;
tn = b;
tm = dd;
num = d;
}
node()
{
}
};
struct node2{
int tn;
int tm;
int c;
node2(int a,int b,int d)
{
tn = a;
tm = b;
c = d;
}
node2()
{
}
};
bool cmp(node a,node b)
{
if(a.num!=b.num)
{
return a.num>b.num;
}
else if(a.c!=b.c)
{
return a.c<b.c;
}
else if(a.tn!=b.tn)
{
return a.tn<b.tn;
}
else
{
return a.tm<b.tm;
}
}
int t,n,m,dx[]={0,1,-1,0},dy[]={1,0,0,-1};
string s[100];
int main()
{
cin>>t;
while(t--)
{
cin>>n>>m;
for(int i=0;i<=n;i++)
for(int j=0;j<=m;j++)
s[i][j]='#';
for(int i=0;i<n;i++)
cin>>s[i];
while(1)
{
vector<node>arr;
arr.clear();
int book[100][100] = {0};
for(int i=0;i<=50;i++)
for(int j=0;j<=50;j++)
book[i][j]=0;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
{
if(!book[i][j]&&s[i][j]!='#')
{
int tc = 1;
char c = s[i][j];
book[i][j] = 1;
queue<node2>q;
q.push(node2(i,j,s[i][j]));
while(!q.empty())
{
int sz = q.size();
for(int i=1;i<=sz;i++)
{
node2 temp = q.front();
q.pop();
int x = temp.tn;
int y = temp.tm;
for(int k = 0;k<4;k++)
{
int tempx = x+dx[k];
int tempy = y+dy[k];
if(tempx>=0&&tempx<n&&tempy>=0&&tempy<m&&!book[tempx][tempy]&&s[tempx][tempy]==c)
{
book[tempx][tempy] = 1;
tc++;
q.push(node2(tempx,tempy,c));
}
}
}
}
if(tc>1)
{
arr.push_back(node(s[i][j],i,j,tc));
}
}
}
if(arr.size()==0)
break;
else
{
int ss;
sort(arr.begin(),arr.end(),cmp);
int xx = arr[0].tn;
int yy = arr[0].tm;
int cc = arr[0].c;
queue<node2>q;
q.push(node2(xx,yy,cc));
while(!q.empty())
{
int sz = q.size();
for(int i=1;i<=sz;i++)
{
node2 temp = q.front();
q.pop();
int x = temp.tn;
int y = temp.tm;
int c = temp.c;
for(int k = 0;k<4;k++)
{
int tempx = x+dx[k];
int tempy = y+dy[k];
if(tempx>=0&&tempx<n&&tempy>=0&&tempy<m&&s[tempx][tempy]==cc)
{
s[tempx][tempy]='#';
q.push(node2(tempx,tempy,c));
}
}
}
}
for(int i=0;i<m;i++)
{
int k = 0;
for(int j=n-1;j>=0;j--)
{
if(s[j][i]=='#')
{
k++;
}
else
s[j+k][i]=s[j][i];
if(k!=0)
s[j][i]='#';
}
}
for(int i=0;i<m;i++)
{
int k=0;
for(int j=0;j<n;j++)
if(s[j][i]=='#')
k++;
if(k==n)
{
for(int j=0;j<n;j++)
s[j][i]=s[j][i+1],s[j][i+1]='#';
}
}
}
}
int shu = 0;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
{
if(s[i][j]=='#')
shu++;
}
cout<<n*m-shu<<endl;
}
return 0;
} 第三题
相关推荐