自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

围巾的ACM博客

刚毕业~

  • 博客(43)
  • 收藏
  • 关注

原创 团体程序设计天梯赛L2-010 排座位(并查集)

思路:留意到这句话,这里假设朋友的朋友也是朋友。但敌人的敌人并不一定就是朋友,朋友的敌人也不一定是敌人。只有单纯直接的敌对关系才是绝对不能同席的。那么朋友之间的关系就可以用并查集维护,然后敌人关系可以用一个矩阵来表示就可以了#includeusing namespace std;int fa[105];int e[105][105];void init(){ for(int

2016-06-28 21:46:09 682

原创 团体程序设计天梯赛L2-009 抢红包

思路:水题...按照题目说的排序就好了#include#include#includeusing namespace std;struct Node{ int sum; int id; int num;}peo[10000+100];bool cmp(Node a,Node b){ if(a.sum==b.sum && a.num==b.num)

2016-06-28 21:44:34 644

原创 团体程序设计天梯赛L2-007 家庭房产(并查集)

思路:用并查集维护家庭的人...就是神烦...#include#include#include#includeusing namespace std;struct Node{ int id,fa,ma,k,son[6],n,area;}nodes[1005];struct Node1{ int id; int num; int sum1,sum2; do

2016-06-28 21:42:07 1479 1

原创 团体程序设计天梯赛L2-006 树的遍历(数据结构)

思路:根据后序和中序建树,然后BFS输出就好了#include#include#includeusing namespace std;struct Node{ int val; Node*lchild; Node*rchild;};Node *build(int *mid,int *post,int len){ if(len==0) return NULL;

2016-06-28 21:40:35 602

原创 团体程序设计天梯赛L2-005 集合相似度(STL)

思路:开个set随便搞搞就好了#include#include#includeusing namespace std;sets[51];int main(){ int n; scanf("%d",&n); for(int i = 0;i<n;i++) { int num; scanf("%d",&num); while(num--) {

2016-06-28 21:39:20 369

原创 团体程序设计天梯赛L2-004 这是二叉搜索树吗?(数据结构)

思路:对于一颗合法的二叉搜索树,那么即满足对于区间[l,r],存在一个点i,a[l]#include#include#includeusing namespace std;const int maxn = 1005;int a[maxn];int check1(int l,int r){ if(l>=r) return 1; int key = r; for(

2016-06-28 21:37:56 2757

原创 团体程序设计天梯赛L2-003 月饼(贪心)

思路:按照比值排个序...然后就是随便做了,注意都要用double#include using namespace std;typedef long long LL;const int N=1e5+10;const int INF=0x3f3f3f3f;int cas=1,T;struct node{ double a,b; double c; bool o

2016-06-28 21:34:43 706

原创 团体程序设计天梯赛L2-002 链表去重(模拟)

思路:题目很简单,数据只有1e5,直接开数组模拟即可#include#include#includeusing namespace std;struct Node{ int val; int next;}a[100005];int vis[100005];int ans[100005],res[100005];int main(){ int adres

2016-06-28 21:32:16 1213

原创 团体程序设计天梯赛L2-001 紧急救援(最短路)

思路:有点权和边权两个属性,求边权最小点权最大的最短路,dijkstra简单变形#includeusing namespace std;const int maxn = 505;const int INF = 1e9;int e[maxn][maxn],val[maxn],path[maxn],dis[maxn],ans[maxn],totval[maxn];int path

2016-06-28 21:30:39 645

原创 Educational Codeforces Round 13 C Joty and Chocolate(数学)

思路:有1到n n个数,如果k%a==0,那么给p元,如果k%b==0,那么给q元,如果k%a==0||k%b==0,那么给p元或者q元,问你最多给多少,显然猜一下k%lcm(a,b)=0给max(p,q)就好了#includeusing namespace std;#define LL long longLL gcd(LL a,LL b){ if(b==0) retur

2016-06-25 14:59:24 896

原创 Educational Codeforces Round 13 A Johny Likes Numbers(水题)

思路:水题#includeusing namespace std;int main(){ int n,k; cin >> n >> k; if (n<k) printf("%d\n",k); else cout << (n%k==0?n+k:k-n%k+n) << endl;}A. Johny Likes

2016-06-25 14:46:25 342

原创 Educational Codeforces Round 13 Iterated Linear Function(数学)

思路:推一下公式可以知道其实就是a^n*x+a^(n-1)*b+a^(n-2)*b+....b,就是一个等比数列求和嘛,注意特判1,可是因为范围太大,所以就要用到模乘法以及逆元。           a^(mod) % mod = a           a^(mod-1) % mod = 1           a^(mod-2) * a %mod = 1           所

2016-06-25 14:44:34 565

原创 HDU 1561 The more, The Better(树形DP)

思路:令dp[i][j]为走到以i为根节点,打了j个宝物的最大值,那么有dp[i][j]=max(dp[i][j],dp[i][k]+dp[v][j-k])#includeusing namespace std;vectore[250];int dp[250][250];int n,m;void dfs(int u,int fa){ for(int i = 0;

2016-06-10 21:41:17 330

原创 POJ 1947 Rebuilding Roads(树形DP)

思路:dp[i][j]表示以i为根节点要得到j个结点的子树所需要切的最少边数,然后枚举切子树还是不切,转移就好了#include#include#include#includeusing namespace std;#define LL long long#define INF 1e9const int maxn = 200;vectore[maxn];int fa[

2016-06-10 21:08:42 284

原创 Codeforces Round #356 (Div. 2) B Bear and Finding Criminals

思路:其实并没怎么看懂题目....不过瞎搞搞就过啦#includeusing namespace std;int a[105];int main(){ int n,p; scanf("%d%d",&n,&p); for(int i = 1;i<=n;i++) scanf("%d",&a[i]); int l=p-1,r=p+1; int ans = 0;

2016-06-09 11:32:07 427

原创 Codeforces Round #356 (Div. 2) A - Bear and Five Cards

思路:水题#includeusing namespace std;int main(){ int a[6]; scanf("%d%d%d%d%d",&a[1],&a[2],&a[3],&a[4],&a[5]); sort(a+1,a+6); int sum = 0; for(int i = 1;i<=5;i++) sum+=a[i]; int cc = 0,cc

2016-06-09 11:31:00 378

原创 poj2782 Bin Packing(贪心)

思路:从大到小排序,然后每次都取最大的和最小的看看能不能放就好了#include#includeusing namespace std;const int maxn = 100000+500;int li[maxn];bool cmp(int a,int b){ return a>b;}int main(){ int n,l; while(scanf("%

2016-06-08 16:33:10 613

原创 hdu4310 Hero(贪心)

思路:贪心一下,优先消灭攻击力高但血量少的,排下序就OK了#include#include#includeusing namespace std;struct Node{ int d; int h;}h[50];bool cmp(Node a,Node b){ return a.d*b.h>a.h*b.d;}int main(){ i

2016-06-08 16:11:02 513

原创 hdu2057 A + B Again

思路:模拟一个十六进制的加法,直接用scanf处理一下就好了#include#include#includeusing namespace std;#define LL long longint main(){ LL a,b; while(scanf("%I64X%I64X",&a,&b)!=EOF) { LL c = a+b; if (c<0)

2016-06-08 16:09:17 406

原创 HDU 4770 Lights Against Dudely(暴力)

思路:这个题....暴力就好了...#include #include #include #include #include #include #include #include #include #include #include #include #define INF 0x3f3f3f3f#define esp 1e-9typedef long lo

2016-06-08 15:44:53 423

原创 HDU 4771 Stealing Harry Potter's Precious(BFS)

思路:由于珠宝只有4个...所以直接枚举一个全排列然后暴力的BFS就好了#includeusing namespace std;#define INF 1e9int p[105];int n,m,k;char mp[105][105];int vis[105][105];int sx,sy;int dir[4][2]={{0,1},{1,0},{-1,0},{0,-1}

2016-06-08 15:34:47 406

原创 HDU 4780 Candy Factory(网络流)

思路:这种乱七八糟这么多条件的...全部扔进图里面好了,另外注意的是因为糖果只能生产一次,所以需要拆下点就OK了#includeusing namespace std;const int maxn = 500;#define INF 1e9struct Edge{ int from,to,cap,flow,cost; Edge(){} Edge(int f,int t,

2016-06-08 15:04:17 489

原创 HDU 4772 Zhuge Liang's Password(暴力)

思路:只有30乘30的矩阵,暴力旋转就好了#includeusing namespace std;int a[32][32];int b[32][32];int c[32][32];int n;void gan(){ for(int i = 1;i<=n;i++) for(int j = 1;j<=n;j++) c[i][j]=a[j][n-i+1]; fo

2016-06-08 15:02:40 337

原创 BZOJ 1192 鬼谷子的钱袋(二进制)

思路:显然要看到这句话:任何数目的金币他都能用这些封闭好的小钱的组合来付账             那么就可以知道是二进制啦,因为任何数字都可以用二进制组合成#include#includeusing namespace std;#define LL long longint main(){ int m; while(scanf("%d",&m)!=EOF) {

2016-06-08 14:46:44 261

原创 BZOJ 1008 越狱(组合数学)

思路:首先全部情况有m^n种,不满足题意的情况有m*(m-1)^(n-1)种情况,然后快速幂就好啦#include#includeusing namespace std;#define LL long long#define mod 100003LL powmod(LL a,LL b){ LL ans = 1,x=a; while(b) { if(b&1)

2016-06-08 14:41:48 390

原创 uva11020 Efficient Solutions

思路:大白上的题...平衡树的应用#include#include#include#includeusing namespace std;struct Point{ int x,y; Point(int xx,int yy):x(xx),y(yy){} bool operator < (const Point&rhs)const { return x < rhs

2016-06-05 21:12:57 466

原创 uvalive 3027 Corporative Network(并查集)

思路:大白书上的题,经典的路径压缩并且维护权值#include#include#include#includeusing namespace std;const int maxn = 20000+500;int fa[maxn],d[maxn];int find(int x){ if(x!=fa[x]) { int root = find(fa[x]

2016-06-05 20:25:28 304

原创 uvalive 3644 X-Plosives(并查集)

思路:大白书上的并查集题#include#includeusing namespace std;const int maxn = 100000+10;int fa[maxn];int find(int x){ return fa[x]==x?x:fa[x]=find(fa[x]);}int main(){ int x,y; while(scanf("%d"

2016-06-05 16:57:09 383

原创 uva11991 Easy Problem from Rujia Liu?(STL)

思路:给你一串数字,每次询问k,v,输出代表第K个V的下标,直接用STL搞搞#include#include#include#includeusing namespace std;int main(){ int n,q; while(scanf("%d%d",&n,&q)!=EOF) { map >mp; for(int i = 1;i<=n

2016-06-05 16:31:10 402

原创 uva11995 I Can Guess the Data Structure!(基本数据结构)

题意:给定一系列操作,让你判断是否是栈,队列,优先队列思路:直接用STL的模拟一波就好了#include#include#include#include#includeusing namespace std;int main(){ int n; while(scanf("%d",&n)!=EOF) { queueq; stacks;

2016-06-05 16:07:41 623

原创 BZOJ 2565 最长双回文串

思路:回文树搞一波...#include #include #include #include #include #include using namespace std;typedef long long int LL;const int maxn=1e5+5;char str[maxn];struct Tree{ int next[maxn][26]

2016-06-03 22:06:55 357

原创 POJ 3974 Palindrome(manacher)

思路:manacher模板#include#include#include#includeusing namespace std;const int maxn = 3e6;int p[maxn];char s[maxn],str[maxn];int len1,len2,ans;void init(){ str[0]='$'; str[1]='#'; for(i

2016-06-03 09:49:05 471

原创 hdu 3068 最长回文(manacher)

思路:马拉车的模板题,可以在O(n)的时间里求出以每一个点为中心的最长回文串长度#includeusing namespace std;const int maxn = 3e5;int p[maxn];char s[maxn],str[maxn];int len1,len2,ans;void init(){ str[0]='$'; str[1]='#'; for(i

2016-06-03 09:47:46 291

原创 Codeforces 677C Vanya and Label(数学)

题意:给你一个字符串,问你有多少对相同长度的字符串 & 起来之后,恰好等于这个字符串,这个字符串的每个字符都是代表着0-63之间的数字思路:首先每个字符是独立的,我们把每个字符的方案数知道,然后再全部乘起来就好了0-63是 2^6,那么我们就按位去考虑就好了如果对于这一位是0的话,那么就有3种方案0&1,1&0,0&0,如果这一位为1的话,只有一种方案所以看一共有多少个位是0就好了

2016-06-02 17:15:59 934

原创 codeforces 677B Vanya and Food Processor(模拟)

思路:SB模拟...#includeusing namespace std;const int maxn = 1e5+7;int n;long long h,k,a[maxn];int main(){ scanf("%d%lld%lld",&n,&h,&k); for(int i=1;i<=n;i++) scanf("%d",&a[i]);

2016-06-02 17:14:35 557

原创 codeforces 677A Vanya and Fence(水题)

思路:水题#includeusing namespace std;int main(){ int n,h,x; int ans = 0; cin >> n >> h; for(int i = 1;i<=n;i++) { cin >> x; if(x<=h) ans+=1; else ans+=2; } cout

2016-06-02 17:13:33 574

原创 bupt 85 Three Points On A Line(水题)

思路:判断是否存在三个点在同一条直线上,直接用斜率就可以了#include#includeusing namespace std;double x[105];double y[105];int main(){ int T; scanf("%d",&T); while(T--) { int n; scanf("%d",&n); for(int i = 1;

2016-06-02 17:08:17 786

原创 bupt 84 Single Number(水题)

思路:排个序然后扫一遍即可#include#include#includeusing namespace std;#define LL long longconst int maxn = 100000+100;LL a[maxn];int main(){ int n; while(scanf("%d",&n)!=EOF) { for(int i

2016-06-01 22:51:12 709 1

原创 UVALive 7045 Last Defence(找规律)

思路:找一下规律,就是一个类似辗转相除法的东西...#include #include #include #include #include #include #include #include #include #include #include #include using namespace std;typedef long long ll;ll a,

2016-06-01 22:49:28 748

原创 UVALive 7043 International Collegiate Routing Contest(字典树)

思路:读懂题目....这很关键....#include #include #include #include #include #include #include #include #include #include #include #include using namespace std;const int N=3*1e4+10;const int ma

2016-06-01 22:48:12 653

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除