标签:long vector char line har class scanf type mis
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t; cin >> t;
while (t--)
{
int x; cin >> x;
cout << x / 2 << endl;
}
return 0;
}
ans!=-1
时,我们可以对字符排个序,然后输出即可。#include <bits/stdc++.h>
using namespace std;
int t;
char s[1010];
int main(){
cin>>t;
while(t--){
cin>>s;
int flag = 0,len = strlen(s);
for(int i=1;i<len;i++){
if(s[i]!=s[0]){
flag = 1;break;
}
}
if(flag == 0)
printf("-1\n");
else{
sort(s,s+len);
cout<<s<<endl;
}
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,x;
ll a[200100];
int main(){
cin>>n>>x;
a[1] = 0,a[n]=x;
for(int i=2;i<=n/2;i++){
cin>>x;
if(x>=a[i-1]+a[n-i+2]){
a[i] = x - a[n-i+2];
a[n-i+1] = a[n-i+2];
}
else{
a[i] = a[i-1];
a[n-i+1] = x-a[i];
}
}
for(int i=1;i<=n;i++)
printf("%lld ",a[i]);
puts("");
return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 998244353;
int T,n,m;
vector<int> v[300010];
int vis[300010];
inline ll fast_pow(ll a,ll b){
ll ans = 1%mod;
for(;b;b>>=1){
if(b&1) ans = (ans*a)%mod;
a = (a*a)%mod;
}
return ans;
}
ll bfs(int x){
vis[x] = 1;
queue<int> q;
q.push(x);
int sum = 0,num = 0;//sum为该联通块总数,num为奇数个数
while(!q.empty()){
int u = q.front();q.pop();
sum++;
if(vis[u]==1)num++;
for(int i=0;i<v[u].size();i++){
int y = v[u][i];
if(vis[y]!=0){
//如果已经被访问过的v与u奇偶性相同,则返回0.最终答案也为0
if(vis[y]+vis[u]!=3){
return 0;
}
continue;
}
vis[y] = 3-vis[u];
q.push(y);
}
}
ll ans = (fast_pow(2,num)+fast_pow(2,sum-num))%mod;
return ans;
}
int main(){
cin>>T;
while(T--){
cin>>n>>m;
for(int i=1;i<=n;i++){
v[i].clear();
vis[i] = 0;
}
for(int i=1,x,y;i<=m;i++){
scanf("%d%d",&x,&y);
v[x].push_back(y);
v[y].push_back(x);
}
ll ans = bfs(1);
for(int i=1;i<=n;i++){
if(!vis[i]){
ans = (ans*bfs(i))%mod;
}
}
cout<<ans<<endl;
}
return 0;
}
标签:long vector char line har class scanf type mis
原文地址:https://www.cnblogs.com/1625--H/p/10362791.html