描述
输入
输出
样例输入
样例输出
#include <cstdio> int main() { int n,a,b,c,d; scanf("%d", &n); while(n--) { scanf("%d%d%d%d", &a, &b, &c, &d); if(a + b + c + d == 0) printf("sidajiekong\n"); else printf("%d\n", a+b+c+d); } }
Description
Input
Output
Sample Input
Sample Output
12#include <cstdio> #include <algorithm> using namespace std; int a[21]; bool cmp(int a, int b) { return a > b; } bool judge(int a, int b, int c) { if(a + b > c && a + c > b && b + c > a) return true; return false; } int main() { int T, ma; scanf("%d", &T); while(T--) { int n; ma = -1; scanf("%d", &n); for(int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a, a + n, cmp); for(int i = n - 1; i >= 0; i--) for(int j = i - 1; j >= 0; j--) for(int k = j - 1; k >= 0; k--) if(judge(a[i], a[j], a[k])) ma = max(ma, a[i] + a[j] + a[k]); printf("%d\n", ma); } }
Description
Input
Output
Sample Input
Sample Output
4#include <cstdio> int a[60]; int main() { int n; scanf("%d", &n); int x; a[1] = 1; a[2] = 2; a[3] = 3; for(int i = 4; i <= 100; i++) a[i] = a[i - 1] + a[i - 3]; while(n--) { scanf("%d", &x); printf("%d\n",a[x]); } }
Description
Input
Output
Sample Input
Sample Output
-1 0 0 0 -V +1 0 0 0 +V -1 +1 -B 0 0 -V +1 -1#include <cstdio> char str[205]; int main() { int n; scanf("%d", &n); getchar(); for(int i = 0; i < 2 * n - 1; i++) scanf("%c ", &str[i]); scanf("%c", &str[2 * n - 1]); for(int i = 0; i < n; i ++) if(str[i] == '0' && str[i + 1] == '0' && str[i + 2] == '0' && str[i + 3] == '0') str[i + 3] = 'V'; int cnt; for(int i = 0 ; i < n; i++) { cnt = 0; for(int j = i + 1; j < n; j++) { if(str[i] == 'V' && str[j] == 'V') { for(int k = i; k <= j; k++) if(str[k] == '1') cnt++; if(cnt % 2 == 0) { str[j - 1] = str[j - 2] = '0'; str[j - 3] = 'B'; } break; } } } bool flag = true; for(int i = 0; i < n - 1; i++) { if(str[i] == '0') printf("%c ", str[i]); else { if(str[i] == '1' && flag) { printf("-1 "); flag = !flag; } else if(str[i] == '1' && !flag) { printf("+1 "); flag = !flag; } else if(str[i] == 'V' && !flag) printf("-V "); else if(str[i] == 'V' && flag) printf("+V "); else if(str[i] == 'B' && !flag) { printf("+B "); flag = !flag; } else if(str[i] == 'B' && flag) { printf("-B "); flag = !flag; } } } if(str[n-1] == '0') printf("0\n"); else if(str[n-1] == '1' && flag) printf("-1\n"); else if(str[n-1] == '1' && !flag) printf("+1\n"); else if(str[n-1] == 'V' && !flag) printf("-V\n"); else if(str[n-1] == 'V' && flag) printf("+V\n"); }
Description
Input
Output
Sample Input
Sample Output
Hint
读入数据请使用 scanf();
对于样例,共有{1},{2},{3},{1,2},{2,3},{1,2,3},6个魔法区间,所以威力为6。
hash + 线性两点扫
#include <cstdio> #include <cstring> int const MAX = 1e6 + 5; int a[MAX], hash[MAX]; int main() { int T; scanf("%d", &T); while(T--) { int n; scanf("%d", &n); memset(hash, 0, sizeof(hash)); for(int i = 1; i <= n; i++) scanf("%d", &a[i]); int ed = 1, st = 1; int ans = 0; for( ; ed <= n; ed++) { if(!hash[a[ed]]) hash[a[ed]] ++; else break; } while(st <= n) { hash[a[st]] --; ans += ed - st; st++; for( ; ed <= n; ed++) { if(!hash[a[ed]]) hash[a[ed]] ++; else break; } } printf("%d\n", ans); } }
Description
Input
Output
Sample Input
Sample Output
Hint
对于样例一,6的素因子集合为{2,3},与其他人不同,所以不行;
对于样例二,所有数的素因子集合均为{3},因此可以组团。
无限gcd
#include <cstdio> #include <algorithm> using namespace std; int a[5], flag; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } void cal(int x,int y) { int tmp; if(x == 1 && y == 1) return; tmp = gcd(x, y); x /= tmp; y /= tmp; if(x == 1 && y == 1) return; else if(tmp == 1 && y % x != 0) { flag = 0; return; } else cal(x, g); return; } int main() { int T; scanf("%d",&T); while(T--) { flag = 1; scanf("%d %d %d", &a[0], &a[1], &a[2]); sort(a,a+3); cal(a[0],a[1]); cal(a[1],a[0]); if(flag) { cal(a[0],a[2]); cal(a[2],a[0]); } if(flag) printf("YES\n"); else printf("NO\n"); } }