状压dp(不会)
http://t.csdn.cn/W9Pi2
#include <iostream>
#include<string.h>
#include<math.h>
using namespace std;
char a[1005];
char c[1005];
int main() {int n;scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%s",a);int l=strlen(a);memset(c,'\0',sizeof(c));int num=0;for(int j=0;j<l;j++){if(j<2){c[num++]=a[j];}else if(j>=2&&num>=2&&a[j]==c[num-1]&&a[j]==c[num-2]){continue;}else if(j>=3 && num>=3 &&c[num-3]==c[num-2]&&a[j]==c[num-1]){continue;}else{c[num++]=a[j];}}c[num]='\0';printf("%s\n",c);}return 0;
}
// 64 位输出请用 printf("%lld")
双端滑动窗口,三个值要确定最后一个值,之后排列组合选出前两个值
#include <iostream>
using namespace std;
int a[1000006];
int mod=99997867;
long long power(long long m){return m*(m-1)/2;
}
int main() {// int a, b;// while (cin >> a >> b) { // 注意 while 处理多个 case// cout << a + b << endl;// }int N,D;scanf("%d%d",&N,&D);for(int i=0;i<N;i++){scanf("%d",&a[i]);}int left=0;int right=2;long long res=0;for(int i=2;i<N;i++){if(a[i]-a[left]<=D){int m=(i-left);if(m>=2){res+=power(m);res=res%mod;}}else{while(a[i]-a[left]>D&&left<i){left++;}if(left==i){continue;}else{int m=(i-left);if(m>=2){res+=power(m);res=res%mod;}}}}printf("%lld\n",res);}
// 64 位输出请用 printf("%lld")
暴力要把最后一张加进去,然后判断是否满足条件
#include <iostream>
#include<vector>
#include<map>
#include<string.h>
using namespace std;
int a[15];vector<int>res;
int main() {for(int i=1;i<=13;i++){scanf("%d",&a[i-1]);}for(int i=1;i<=9;i++){// map<int,int>mp;int b[10];int c[10];memset(b,0,sizeof(b));memset(c,0,sizeof(c));for(int j=0;j<13;j++){// mp[a[j]]++;b[a[j]]++;}b[i]++;if(b[i]>=5) continue;int w3=0;int w2=0;for(int j=1;j<=9;j++){int k=b[j];if(k==3){w3++;}else if(k==2){w2++;}}if(w3==4 &&w2==1){res.push_back(i);continue;}else{for(int j=1;j<=9;j++){c[j]=b[j];}for(int p=1;p<=9;p++){for(int j=1;j<=9;j++){b[j]=c[j];}if(b[p]>=2){b[p]-=2;}else{continue;}int w4=0;int id=0;for(int j=1;j<=9;j++){if(b[j]==3){w4++;continue;}if(b[j]==4){b[j]-=3;w4++;}if(b[j]&&j<=7){if(b[j+1]-b[j]>=0&&b[j+2]-b[j]>=0){b[j+1]-=b[j];b[j+2]-=b[j];w4+=b[j];continue;}else{id=1;break;}}}b[p]+=2;if(id==1){continue;}else{if(w4==4){res.push_back(i);break;}}}}}if(res.size()==0){printf("0\n");return 0;}for(int i=0;i<res.size();i++){if(i==0){printf("%d",res[i]);}else{printf(" %d",res[i]);}}printf("\n");return 0;}
// 64 位输出请用 printf("%lld")
使用哈希
#include <iostream> #include<map> using namespace std; // vector<int>ve[1e5+7]; map<pair<int,int>,int>mp; map<pair<int,int>,int>seq;//已经连续出现几次; int main() {int n;scanf("%d",&n);while(n--){int M;scanf("%d",&M);mp.clear();seq.clear();int res=0;for(int i=0;i<M;i++){int w;scanf("%d",&w);for(int j=0;j<w;j++){int x,y;scanf("%d%d",&x,&y);pair<int,int>p;p.first=x;p.second=y;if(mp[p]==i)//上一帧出现{mp[p]=i+1;//第几帧出现;seq[p]++;res=max(res,seq[p]);}else{mp[p]=i+1;seq[p]=1;res=max(res,1);}}}printf("%d\n",res);}return 0; } // 64 位输出请用 printf("%lld")
暴力,先计算面值大的
#include <iostream>
using namespace std;int main() {// int a, b;// while (cin >> a >> b) { // 注意 while 处理多个 case// cout << a + b << endl;// }int n;scanf("%d",&n);int w=1024-n;int x=w/64;w=w-x*64;int x1=w/16;w=w-x1*16;int x2=w/4;w=w-x2*4;int result=x+x1+x2+w;printf("%d\n",result);return 0;
}
// 64 位输出请用 printf("%lld")
二分
#include <iostream>
#include<math.h>
using namespace std;
int a[5000];bool H(int n,int e){for(int i=0;i<n;i++){e=2*e-a[i];if(e<0){return false;}if(e>1e5){return true;}}return true;}
int main() {int n;scanf("%d",&n);int max_num=0;for(int i=0;i<n;i++){scanf("%d",&a[i]);max_num=max(a[i],max_num);}int left=1;int right=max_num;while(left<=right){int mid=(left+right)/2;bool m=H(n,mid);if(m){right=mid-1;}else{left=mid+1;}}printf("%d\n",left);return 0;
}
// 64 位输出请用 printf("%lld")