简单总结一下昨晚的cf。两个字:脑残
手速太慢(maybe天气冷到手有点僵),水题都不会水了,组合数那题竟然开eclipse去做!脑残到不会用数组递推,D题图论题意大概看懂就开始搞,搞到很慢,临结束还有2min才交,不过幸运的是1A,E也是水题,不够时间搞。哎,注定只能做div2了=。=
ABC水不贴代码。
D图论,把一个图中成环的点输出0,其他点就输出到环的距离就ok,我的做法是开始先类似拓扑排序那样,依次删去度为1的点,剩下的就是环中的点,再bfs求其余点离环的距离,代码写得有点搓。
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <time.h>
#include <cstdio>
#include <math.h>
#include <iomanip>
#include <cstdlib>
#include <limits.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
#define LL long long
#define MIN INT_MIN
#define MAX INT_MAX
#define PI acos(-1.0)
#define FRE freopen("input.txt","r",stdin)
#define FF freopen("output.txt","w",stdout)
#define N 3005
vector<int> v[N];
int n;
queue<int> qq;
int du[N];
struct node{
int id;
int t;
};
queue<node> q;
int ans[N];
bool vis[N];
int main(){
cin>>n;
int i,j;
memset(vis,0,sizeof(vis));
for (i=0;i<n;i++) {
int x,y;
cin>>x>>y;
v[x].push_back(y);
v[y].push_back(x);
du[x]++;
du[y]++;
}
for (i=1;i<=n;i++) {
if (du[i] == 1) {
qq.push(i);
}
}
while(!qq.empty()){
int x = qq.front();
qq.pop();
du[x]--;
for (i = 0 ;i < v[x].size(); i++) {
int y = v[x][i];
du[y]--;
if (du[y] == 1 ){
qq.push(y);
}
}
}
while(!qq.empty())qq.pop();
for (i=1;i<=n;i++){
if (du[i]==2){
ans[i] = 0;
node tmp;
tmp.t = i;
tmp.id = 0;
q.push(tmp);vis[i] = 1;
}
}
while(!q.empty()){//cout<<"!"<<endl;
node x = q.front();
q.pop();
vis[x.t] = 1;
for (i=0;i<v[x.t].size();i++){
int y = v[x.t][i];
if (vis[y])continue;
vis[y]=1;
ans[y] = x.id+1;
node tmp;
tmp.t = y;
tmp.id = x.id+1;
q.push(tmp);
}
}
for(i=1;i<=n;i++)cout<<ans[i]<<" ";
cout<<endl;
return 0;
}
E模拟,4次排序:正对角、副对角、x方向、y方向排序,注意处理好细节,要保证排好后同一直线上相邻两个点之间必须没有点,否则会wa
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <time.h>
#include <cstdio>
#include <math.h>
#include <iomanip>
#include <cstdlib>
#include <limits.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
#define LL long long
#define MIN INT_MIN
#define MAX INT_MAX
#define PI acos(-1.0)
#define FRE freopen("input.txt","r",stdin)
#define FF freopen("output.txt","w",stdout)
#define N 100005
struct node{
int x,y;
int id;
}p[N],q[N];
int num[N];
int ans[10];
bool cmp1(node a,node b){
if (a.x+a.y==b.x+b.y)return (a.x < b.x && a.y > b.y);
return a.x+a.y<b.x+b.y;
}
bool cmp2(node a, node b) {
if (a.y - a.x != b.y - b.x) {
return a.y - a.x < b.y - b.x;
} else {
return a.x < b.x;
}
}
bool cmp3(node a,node b){
if (a.x == b.x) return a.y < b.y;
return a.x < b.x;
}
bool cmp4(node a,node b){
if (a.y == b.y) return a.x < b.x;
return a.y < b.y;
}
///
int main(){
int n,m;
cin>>n>>m;
int i;
for (i=0;i<m;i++) {
cin>>p[i].x>>p[i].y;
p[i].id = i;
}
for (i=0;i<m;i++) {
q[i].x = p[i].x;
q[i].y = p[i].y;
q[i].id = p[i].id;
}
sort(q,q+m,cmp1);
for (i = 0; i+1 < m; i++){
if ((q[i].x+q[i].y) == (q[i+1].x + q[i+1].y)) {
num[q[i].id]++;
num[q[i+1].id]++;
}
}
//for (i=0;i<m;i++)cout<<q[i].x<<" "<<q[i].y<<endl;
// cout<<num[i]<<endl;
for (i=0;i<m;i++) {
q[i].x = p[i].x;
q[i].y = p[i].y;
q[i].id = p[i].id;
}
sort(q,q+m,cmp2);
for (i = 0; i+1 < m; i++){
if ((q[i].x-q[i+1].x) == (q[i].y - q[i+1].y)) {
num[q[i].id]++;num[q[i+1].id]++;
}
}
for (i=0;i<m;i++) {
q[i].x = p[i].x;
q[i].y = p[i].y;
q[i].id = p[i].id;
}
sort(q,q+m,cmp3);
for (i = 0; i+1 < m; i++){
if (q[i].x == q[i+1].x) {
num[q[i].id]++;num[q[i+1].id]++;
}
}
/
for (i=0;i<m;i++) {
q[i].x = p[i].x;
q[i].y = p[i].y;
q[i].id = p[i].id;
}
sort(q,q+m,cmp4);
for (i = 0; i+1 < m; i++){
if (q[i].y == q[i+1].y) {
num[q[i].id]++;num[q[i+1].id]++;
}
}
/
for (i = 0 ; i < m; i++) {
ans[num[i]]++;
}
for (i = 0 ; i < 9;i++) {
cout<<ans[i]<<" ";
}cout<<endl;
return 0;
}