Daysgone

CDUT

614

imnoob
Selflocking
NZX

PseudorandomGenerators
Eli2010
hayabusa

ζ酔小汐ゝ
Will66

# 因此在处理输入时的for循环变量的取值是有特殊意义的（题目中样例也展示了这一点）

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 101;
string v[N];
int l[N],r[N];
bool st[N];
int root;

void postorder(int root)
{
cout<<"(";
if (l[root] != -1 && r[root] != -1)
{
postorder(l[root]);
postorder(r[root]);
cout<<v[root];
}
else if (l[root] == -1 && r[root] == -1)cout<<v[root];
else
{
cout<<v[root];
postorder(r[root]);
}
cout<<")";
}

int main()
{
int n;
cin>>n;
for (int i = 1; i <= n; i ++ )
{
cin>>v[i]>>l[i]>>r[i];
if (l[i] != -1)st[l[i]] = true;
if (r[i] != -1)st[r[i]] = true;
}

for (int i = 1; i <= n; i ++ )
{
if (!st[i])root = i;
}

postorder(root);
return 0;
}


## 把链表变成vector就比较好处理了，而不一定非要用两个数组单链表去做

#include <iostream>
#include <cstring>
#include <algorithm>
#include<vector>

using namespace std;

const int N = 100010;
typedef pair<int, int> PII;

int v[N],ne[N];
int idx;
int h1,h2,n;
vector<PII>a,b;
vector<PII>res;

int main()
{
scanf("%d%d%d",&h1,&h2,&n);
while (n -- )
{
}

for(int i = h1;i != -1;i = ne[i])a.push_back({i,v[i]});
for (int i = h2; i != -1;i = ne[i])b.push_back({i,v[i]});

if (a.size() < b.size())swap(a,b);

for(int i = 0,j = b.size() - 1;i < a.size(); i += 2, j --)
{
res.push_back(a[i]);
if (i+1 < a.size())res.push_back(a[i+1]);
if (j >= 0 )res.push_back(b[j]);
}

for(int i = 0;i < res.size();i ++)
{
printf("%05d %d ",res[i].first,res[i].second);
if (i + 1 < res.size())printf("%05d\n",res[i+1].first);
else puts("-1");
}
return 0;

}


Daysgone
13天前

# 提醒一下自己

## substr(a,b) 第一个参数是开始下标，第二个数字是字串长度

#include <iostream>
#include <cstring>
#include <algorithm>
#include <unordered_set>
using namespace std;

unordered_set<string>lis;

int main()
{
int n,m;
cin>>n;
while (n -- )
{
string name;
cin>>name;
lis.insert(name);
}

int cnt = 0;
cin>>m;
string a,b;
while (m -- )
{
string name;
cin>>name;
if (lis.count(name))
{
cnt++;
if (a.empty() || a.substr(6,8) > name.substr(6,8))a = name;
}
if (b.empty() || b.substr(6,8) > name.substr(6,8))b = name;
}
if (cnt == 0)cout<<cnt<<endl<<b;
else cout<<cnt<<endl<<a;

return 0;
}


Daysgone
27天前
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int a;

bool isprime(int x)
{
if (x <= 0)return false;
if (x == 1)return false;
for(int i = 2;i <= x / i;i ++)if (x % i == 0)return false;
return true;
}

bool sex(int x)
{
if ( isprime(x) && isprime(x+6) )return true;
else if ( isprime(x) && isprime(x-6) && x-6 > 0)return true;
else return false;
}

int main()
{
cin>>a;
if (isprime(a) && isprime(a-6))
{
printf("Yes\n%d",a-6);
return 0;
}
else if( isprime(a) && isprime(a+6) )
{
printf("Yes\n%d",a+6);
return 0;
}
else
{
while(!sex(a++));
printf("No\n%d\n",a-1);
}
return 0;
}


Daysgone
1个月前

# 区间和并 注意else的时候是ed = max( ed, i.second )

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;

typedef pair<int,int>PII;

const int N = 100010;

vector<PII>area;//第一个数是出发点，第二个数是终止点

int n,m;

int merge(vector<PII>&a)
{
int ans = n;
vector<PII>res;

sort(a.begin(),a.end());

int st = -1,ed = -1;

for(auto i:a)
{
if (ed < i.first)
{
if (st != -1)res.push_back({st,ed});
st = i.first , ed = i.second;
}
else ed = max (i.second,ed);
}

if (st != -1)res.push_back({st,ed});
for(auto i:res)
{
// cout<<i.first<<" "<<i.second<<" "<<(i.second - i.first + 1 )<<endl;
ans-=(i.second - i.first + 1 );
}
return ans+1;
}

int main()
{
cin>>n>>m;
for(int i = 0;i < m;i ++)
{
int x,y;
scanf("%d%d", &x, &y);
area.push_back({x,y});
}
cout<<merge(area)<<endl;
return 0;
}


Daysgone
1个月前
略


Daysgone
1个月前
略


Daysgone
1个月前
略


Daysgone
1个月前
略


Daysgone
1个月前
略