标签:|| mes const size tle 复杂 flag main ESS
还有一题由于上午心情复杂。。没调试完。待补。
模拟题
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int getLen(ll x){
int len = 0;
while(x){
len++;
x/=10;
}
return len;
}
int main(){
cin>>n;
while(n--){
ll x;
cin>>x;
int len = getLen(x);
ll temp = x;
int t = 0;
ll right = 0;
ll rightTemp = 0;
ll left = 0;
while(t<len/2){
rightTemp = rightTemp * 10 + temp%10;
temp/=10;
t++;
}
while(rightTemp){
right = right * 10 + rightTemp%10;
rightTemp/=10;
}
left = temp;
if(left == 0 || right == 0){
puts("No");
}else{
if(x%(left*right) == 0) puts("Yes");
else puts("No");
}
}
return 0;
}
链表题
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1010;
const int maxm = 100000;
struct node{
int address;
int data;
int next;
}nod[maxm];
vector<node> vec;
vector<node> ans;
int Head,n,k;
int vis[maxm];
int main(){
cin>>Head>>n>>k;
for(int i=1;i<=n;i++){
int add,dat,nex;
cin>>add>>dat>>nex;
nod[add].address = add;
nod[add].data = dat;
nod[add].next = nex;
}
for(int head = Head;head!=-1;head=nod[head].next){
vec.push_back(nod[head]);
}
for(int i=0;i<vec.size();i++){
if(vec[i].data < 0 && !vis[vec[i].address]){
ans.push_back(vec[i]);
vis[vec[i].address] = 1;
}
}
for(int i=0;i<vec.size();i++){
if(vec[i].data >= 0 && vec[i].data <= k && !vis[vec[i].address]){
ans.push_back(vec[i]);
vis[vec[i].address] = 1;
}
}
for(int i=0;i<vec.size();i++){
if(!vis[vec[i].address]){
ans.push_back(vec[i]);
vis[vec[i].address] = 1;
}
}
if(ans.size() == 1){
printf("%05d %d -1",ans[0].address,ans[0].data);
return 0;
}
for(int i=0;i<ans.size()-1;i++){
printf("%05d %d %05d\n",ans[i].address,ans[i].data,ans[i+1].address);
}
if(ans.size() > 1) printf("%05d %d -1",ans[ans.size()-1].address,ans[ans.size()-1].data);
return 0;
}
简单图论,最小覆盖,邻接表存图
#include<bits/stdc++.h>
using namespace std;
const int maxn = 10000;
int n,m,k;
int g[maxn][maxn];
int vis[maxn][maxn];
vector<int> vec;
void init(){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
vis[i][j] = 0;
}
}
}
int main(){
cin>>n>>m;
for(int i=0;i<m;i++){
int u,v;
cin>>u>>v;
g[u][v] = 1;
g[v][u] = 1;
}
cin>>k;
for(int t=0;t<k;t++){
init();
int nv;
cin>>nv;
for(int i=0;i<nv;i++) {
int d;
cin>>d;
vec.push_back(d);
}
for(int i=0;i<=nv-1;i++){
for(int j=0;j<n;j++){
if(g[vec[i]][j] == 1){
vis[vec[i]][j] = 1;
vis[j][vec[i]] = 1;
}
}
}
bool flag = true;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(g[i][j] == 1 && (vis[i][j] == 0 || vis[j][i] == 0)){
flag = false;
break;
}
}
if(flag == false) break;
}
if(flag) puts("Yes");
else puts("No");
vec.clear();
}
return 0;
}
判断是否红黑树
待补
标签:|| mes const size tle 复杂 flag main ESS
原文地址:https://www.cnblogs.com/fisherss/p/11988440.html