A
#include<iostream> #include<cstdio> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; int l[4]; int main(){ while(scanf("%d%d%d%d" , &l[0] , &l[1] , &l[2] , &l[3]) != EOF){ int s[3]; int mark = 0; for(int i = 0 ; i < 4 ; i++){ for(int j = i+1 ; j < 4 ; j++){ for(int k = j+1 ; k < 4 ; k++){ s[0] = l[i] , s[1] = l[j] , s[2] = l[k]; sort(s , s+3); if(s[2] < s[1]+s[0] && s[2] > s[1]-s[0]){ printf("TRIANGLE\n"); mark = 1; break; } } if(mark) break; } if(mark) break; } if(mark) continue; for(int i = 0 ; i < 4 ; i++){ for(int j = i+1 ; j < 4 ; j++){ for(int k = j+1 ; k < 4 ; k++){ s[0] = l[i] , s[1] = l[j] , s[2] = l[k]; sort(s , s+3); if(s[0] == 0 || s[2] == s[1]+s[0]){ printf("SEGMENT\n"); mark = 1; break; } } if(mark) break; } if(mark) break; } if(!mark) printf("IMPOSSIBLE\n"); } return 0; }
B
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<set> using namespace std; #define MAXN 110 int n , m; char c; int dir[4][2] = {{-1,0},{0,1},{1,0},{0,-1}}; char maze[MAXN][MAXN]; set<char>s; int main(){ while(scanf("%d %d %c" , &n , &m , &c) != EOF){ for(int i = 0 ; i < n ; i++) scanf("%s" , maze[i]); s.clear(); //cout<<c<<endl; for(int i = 0 ; i < n ; i++){ for(int j = 0 ; j < m ; j++){ //cout<<maze[i][j]; if(maze[i][j] == c){ for(int k = 0 ; k < 4 ; k++){ int x = i+dir[k][0]; int y = j+dir[k][1]; if(x < 0 || x >= n || y < 0 || y >= m) continue; if(maze[x][y] != '.' && maze[x][y] != c) s.insert(maze[x][y]); } } } //cout<<endl; } printf("%d\n" , s.size()); } return 0; }
C
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define MAXN 100010 int n; int Time[MAXN]; void solve(){ int Acnt , Bcnt; Acnt = 1 , Bcnt = 1; int Asum , Bsum; Asum = Time[0] , Bsum = Time[n-1]; int i , j; i = 0 , j = n-1; while(i+1 != j){ if(Asum < Bsum){ Acnt++; i++; Asum += Time[i]; } else if(Asum > Bsum){ Bcnt++; j--; Bsum += Time[j]; } else{ Acnt++; i++; Asum += Time[i]; } } printf("%d %d\n" , Acnt , Bcnt); } int main(){ while(scanf("%d" , &n) != EOF){ for(int i = 0 ; i < n ; i++) scanf("%d" , &Time[i]); if(n == 1) printf("1 0\n"); else solve(); } return 0; }
时间: 2024-10-24 22:27:30