如果是 A B C ABC ABC就输出 A R C ARC ARC
如果是 A R C ARC ARC就输出 A B C ABC ABC
开个桶随便维护一下就好
int n,k;
bool vis[N];
int main()
{
read(n),read(k);
Rep(i,1,k){
int x,y;
read(x);
while(x--)read(y),vis[y]=true;
}
int ans=0;
Rep(i,1,n)if(!vis[i])ans++;
printf("%d\n",ans);
return 0;
}
其实不用存图,在读入的时候就两边分别取一下最大值即可
int n,m;
int a[N],high[N];
int ans;
int main()
{
read(n),read(m);
Rep(i,1,n)read(a[i]);
Rep(i,1,m){
int x,y;
read(x),read(y);
high[x]=max(high[x],a[y]);
high[y]=max(high[y],a[x]);
}
Rep(i,1,n)if(high[i]<a[i])ans++;
printf("%d\n",ans);
return 0;
}
观察 X ≤ 1 e 9 X\leq 1e9 X≤1e9,而 300 0 5 − 299 9 5 ≈ 1 0 11 3000^5-2999^5\approx 10^{11} 30005−29995≈1011,也就是说我们可以打表处理到 3000 3000 3000,然后 n 2 n^2 n2枚举就可以
但是注意还要考虑减法的情况
# define int long long
int x;
int wuc[N];
signed main()
{
read(x);
Rep(i,1,3000)wuc[i]=i*i*i*i*i;
Rep(i,0,3000)
Rep(j,0,3000)
if(wuc[i]+wuc[j]==x)return printf("%lld %lld\n",i,-j),0;
Rep(i,0,3000)
Rep(j,0,3000)
if(wuc[i]-wuc[j]==x)return printf("%lld %lld\n",i,j),0;
return 0;
}
翻译一下题意,就是让你求 j − i = a i + a j , j > i j-i=a_i+a_j,j>i j−i=ai+aj,j>i的个数
移项(套路了) j − a j = i + a i j-a_j=i+a_i j−aj=i+ai,然后就很好弄了,开个桶记录一下就好了
但是 a i ≤ 1 0 9 a_i\leq 10^9 ai≤109诶…
正常做法:离散化一下
懒人做法:开 m a p map map,反正这题也不会卡你
int n;
int a[N];
map<int,int> var;
ll ans;
int main()
{
read(n);
Rep(i,1,n)read(a[i]);
Rep(i,1,n){
ans+=var[i-a[i]];
var[i+a[i]]++;
}
printf("%lld\n",ans);
return 0;
}
这题就不说啥了…
我暴力吊打表算…
int n,a,b,c;
int ans[N];
char s[N][3];
void dfs(int u,int a,int b,int c){
printf("%d\n",u);
if(u>n){
puts("Yes");
Rep(i,1,n)printf("%c\n",ans[i]+'A');
exit(0);
}
if(s[u][0]=='A'&&s[u][1]=='B'){
if(a)ans[u]=1,dfs(u+1,a-1,b+1,c);
if(b)ans[u]=0,dfs(u+1,a+1,b-1,c);
}
if(s[u][0]=='A'&&s[u][1]=='C'){
if(a)ans[u]=2,dfs(u+1,a-1,b,c+1);
if(c)ans[u]=0,dfs(u+1,a+1,b,c-1);
}
if(s[u][0]=='B'&&s[u][1]=='C'){
if(b)ans[u]=2,dfs(u+1,a,b-1,c+1);
if(c)ans[u]=1,dfs(u+1,a,b+1,c-1);
}
}
int main()
{
freopen("testdata.in","r",stdin);
read(n),read(a),read(b),read(c);
Rep(i,1,n)scanf("%s",s[i]);
dfs(1,a,b,c);
puts("No");
return 0;
}
当然这个方法是错的,具体方法大家还是去看官方题解吧