A - Painter
HDU - 5319
题意:红色“”这样画,蓝色"/"这样画,红加蓝为绿,问最少画几次
题解:坑点,每一行的字符串的程度不一定是n,遍历后开始画访问标记搞搞就搞好了
#include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include<stack> #include<map> #define INF 0x3f3f3f3f #define lowbit(x) (x&(-x)) using namespace std; typedef long long LL; const int MAXN = 50 + 10; const int MOD = 1e9 + 7; const LL MAXX = (1LL<<32) - 1LL; int a[MAXN][MAXN]; int b[MAXN][MAXN]; char s[MAXN]; int vis[MAXN][MAXN]; int viss[MAXN][MAXN]; int n,m; bool check(int x,int y) { if(0 <= x && x < n && 0 <= y && y < m) return true; return false; } int main() { int t; scanf("%d",&t); while(t--) { int ans = 0; memset(a,0,sizeof a); memset(b,0,sizeof b); memset(vis,0,sizeof vis); memset(viss,0,sizeof viss); scanf("%d",&n); for(int i = 0; i < n; i++) { scanf("%s",s); m = strlen(s); for(int j = 0; j < m; j++) { if(s[j] == 'R' || s[j] == 'G') { a[i][j] = 1; } if(s[j] == 'G' || s[j] == 'B') { b[i][j] = 1; } } } for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { if(a[i][j] == 1 && vis[i][j] == 0) { vis[i][j] = 1; ans++; int tx = i,ty = j; while(true) { tx++; ty++; if(check(tx,ty) && a[tx][ty] == 1 && vis[tx][ty] == 0) { vis[tx][ty] = 1; } else break; } } } } for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { if(b[i][j] == 1 && viss[i][j] == 0) { viss[i][j] = 1; ans++; int tx = i,ty = j; while(true) { tx++; ty--; if(check(tx,ty) && b[tx][ty] == 1 && viss[tx][ty] == 0) { viss[tx][ty] = 1; } else break; } } } } printf("%d ",ans); } }
B - Misaki's Kiss again
HDU - 5175
题意:题目给N,求1-N中的数M,要求gcd(N,M) = N xor M
题解:枚举公因数,异或后的答案,判断答案是否在范围内即可
#include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include<stack> #include<map> #define INF 0x3f3f3f3f #define lowbit(x) (x&(-x)) using namespace std; typedef long long LL; const int MAXN = 50000 + 10; const int MOD = 1e9 + 7; const LL MAXX = (1LL<<32) - 1LL; LL gcd(LL a,LL b) { return b == 0 ? a : gcd(b, a % b); } LL num[MAXN]; LL b[MAXN]; int main() { int ca = 1; LL n; int pos = 0; while(~scanf("%lld",&n)) { memset(num,0,sizeof num); memset(b,0,sizeof b); pos = 0; printf("Case #%d: ",ca++); int ans = 0; for(LL i = 1; i <= sqrt(n);i++) { if (n % i == 0) { LL t1 = num[pos++] = i ^ n; LL t2 = num[pos++] = (n /i) ^ n; //cout << t1 <<endl; //cout << t2 << endl; } } int id = 0; for(int i = 0; i < pos; i++) { if((num[i] ^ n) == gcd(n,num[i]) && 1 <= num[i] && num[i] <= n) { //cout << num[i] <<endl; b[id++] = num[i]; } } printf("%d ",id); if(id == 0) printf(" "); else { sort(b, b + id); for (int i = 0; i < id; i++) printf("%lld%c", b[i], i == id - 1 ? ' ' : ' '); } } }
C - Discounts
CodeForces - 161B
题意:n样物品,k辆车,每辆车都要放东西,物品分铅笔和凳子,如果一辆购物车里面有凳子的话就可以车里面的最便宜的东西打半折,问最低价和怎么放
题解:贪心,凳子先都放到车里,能放完就放完,前面的车里只放凳子,之后再放其他的,如果凳子数量比车多的话那就剩下的都放在最后一个里面,唉,看代码好了
#include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include<stack> #include<map> #define INF 0x3f3f3f3f #define lowbit(x) (x&(-x)) using namespace std; typedef long long LL; const int MAXN = 1e3 + 10; const int MOD = 1e9 + 7; const LL MAXX = (1LL<<32) - 1LL; struct node { int p,t,id; }a[MAXN]; bool cmp(node x,node y) { return x.t == y.t ? x.p > y.p : x.t < y.t; } int main() { int n,k; int MIN = INF; scanf("%d %d",&n,&k); for(int i = 1; i <= n; i++) { scanf("%d %d",&a[i].p,&a[i].t); a[i].id = i; MIN = min(MIN,a[i].p); } sort(a + 1,a + 1 + n,cmp); double sum = 0; int i = 1; for(i; i <= k - 1 && a[i].t == 1;i++) sum += a[i].p * 0.5; if(a[k].t == 1) sum -= (MIN * 0.5); for(i;i <= n; i++) sum += a[i].p; printf("%.1f ",sum); for(int i = 1; i <= k - 1; i++) printf("1 %d ",a[i].id); printf("%d",n - k + 1); for(int i = k; i <= n; i++) printf(" %d",a[i].id); printf(" "); }
D - Remainders Game
CodeForces - 687B
题意:给一个ci数组,已知有一个 x mod 所有的ci都是确定的,问这个x mod k确定不确定
题解:假设这个x不确定,那么x1 mod ci = x2 mod ci,x1 mod k != x2 mod k,那么可得(x1 -x2)mod ci = 0,(x1 - x2)mod k != 0,所以可得x1 - x2是所有ci的倍数,那么x1 - x2就是数组c的所有数的最小公倍数,而x1 - x2 mod k不为0,即可计算出c数组的最小公倍数,然后mod k 看是否余数为0,这里lcm求的时候过大,边求余数边取余
#include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include<stack> #include<map> #define INF 0x3f3f3f3f #define lowbit(x) (x&(-x)) using namespace std; typedef long long LL; const int MAXN = 50 + 10; const int MOD = 1e9 + 7; const LL MAXX = (1LL<<32) - 1LL; LL gcd(LL a,LL b) { return b == 0 ? a : gcd(b, a % b); } LL lcm(LL a,LL b) { return a * b / gcd(a,b); } int main() { int n; LL k,x,Lcm = 0; scanf("%d %lld",&n,&k); int flag = 0; for(int i = 0; i < n; i++) { scanf("%lld",&x); if(Lcm == 0 && i == 0) Lcm = x; else if(Lcm == 0 && i != 0) { Lcm = x; flag = 1; } else Lcm = lcm(Lcm,x); Lcm %= k; } if(flag || Lcm % k == 0) puts("Yes"); else puts("No"); }