- #include <bits/stdc++.h>
- using namespace std;
- int main(){
- int t, cs = 0;
- long long S, tm, ll, zz, x, y, s, p, i;
- scanf("%d", &t);
- while(t--){
- scanf("%lld", &S);
- tm = 1;
- s = ceil(sqrt(S));
- i = s;
- p = s-1; p *= p; p += 1;
- s *= s;
- if(s%2){
- ll = abs(S-s);
- zz = abs(S-p);
- if(ll <= zz)x = ll+1, y = i;
- else x = i, y = zz+1;
- }
- else{
- ll = abs(S-s);
- zz = abs(S-p);
- if(ll <= zz)y = ll+1, x = i;
- else y = i, x = zz+1;
- }
- printf("Case %d: %lld %lld\n", ++cs, x, y);
- }
- return 0;
- }
Saturday, June 6, 2015
LightOJ - 1008 - Fibsieve`s Fantabulous Birthday
LightOJ - 1015 - Brush (I)
- #include <bits/stdc++.h>
- using namespace std;
- int main(){
- int t, n, m, cs = 0;
- cin >> t;
- while(t--){
- cin >> n;
- int ans = 0;
- for(int i = 0; i < n; i++){
- cin >> m;
- if(m > 0)ans += m;
- }
- cout << "Case " << ++cs << ": " << ans << endl;
- }
- return 0;
- }
LightOJ - 1069 - Lift
- #include <bits/stdc++.h>
- using namespace std;
- int main(){
- int t, n, m, in, cs = 0;
- cin >> t;
- while(t--){
- int ans = 19;
- cin >> n >> m;
- ans += ((n+abs(n-m))*4);
- cout << "Case " << ++cs << ": " << ans << endl;
- }
- return 0;
- }
LightOJ - 1053 - Higher Math
- #include <bits/stdc++.h>
- using namespace std;
- int main(){
- int t, n, p[4], cs = 0;
- cin >> t;
- while(t--){
- cin >> p[0] >> p[1] >> p[2];
- sort(p, p+3);
- cout << "Case " << ++cs << ": ";
- puts(((p[0]*p[0])+(p[1]*p[1])) == (p[2]*p[2])?"yes":"no");
- }
- return 0;
- }
LightOJ - 1387 - Setu
- #include <bits/stdc++.h>
- using namespace std;
- int main(){
- int t, n, p, cs = 0;
- string inp;
- cin >> t;
- while(t--){
- cin >> n;
- long long ans = 0;
- cout << "Case " << ++cs << ":" << endl;
- for(int i = 0; i < n; i++){
- cin >> inp;
- if(inp == "donate"){
- cin >> p;
- ans += (long long)p;
- }
- else cout << ans << endl;
- }
- }
- return 0;
- }
LightOJ - 1104 - Birthday Paradox
- /****************##### بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم #####*******************
- __________________________________________________________________________
- ###################### Ya-Seen Arafat(ACWizard) #########################
- ###################### UAP-CSE-33B #########################
- *************************************************************************/
- #include <bits/stdc++.h>
- #define sc(n) scanf("%d", &n)
- #define S 2003
- using namespace std;
- typedef long long LL;
- void Do(){
- int t, n, tmp, ans, cs = 0;
- double cn;
- cin >> t;
- while(t--){
- cin >> n;
- ans = 0; cn = 1.0;
- for(int i = n; ; i--){
- ans++;
- cn *= (i/(double)n);
- tmp = (1.0-cn)*1000000000;
- if(tmp >= 500000000)break;
- }
- cout << "Case " << ++cs << ": " << --ans << endl;
- }
- }
- int main(){
- //ios_base::sync_with_stdio(0); cin.tie(0);
- #ifndef ONLINE_JUDGE
- ///freopen("inp","r",stdout);
- ///freopen("contest.txt","w",stdout);
- #endif
- Do();
- return 0;
- }
LightOJ - 1238 - Power Puff Girls
- /****************##### بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم #####*******************
- __________________________________________________________________________
- ###################### Ya-Seen Arafat(ACWizard) #########################
- ###################### UAP-CSE-33B #########################
- *************************************************************************/
- #include <bits/stdc++.h>
- #define sc(n) scanf("%d", &n)
- #define scS(n) scanf("%s", n)
- #define S 23
- using namespace std;
- typedef long long LL;
- int dirX[] = {1, 0, -1, 0, 1, -1, 1, -1};
- int dirY[] = {0, 1, 0, -1, 1, -1, -1, 1};
- struct node{
- int x, y;
- node(int p, int q){
- x = p, y = q;
- }
- };
- char cell[S][S];
- int dist[S][S];
- int n, m;
- int bfs(int u, int v){
- queue <node> Qu;
- memset(dist, -1, sizeof(dist));
- Qu.push(node(u, v));
- dist[u][v] = 0;
- while(!Qu.empty()){
- node i = Qu.front(); Qu.pop();
- for(int z = 0; z < 4; z++){
- int I = i.x+dirX[z], J = i.y+dirY[z];
- if(dist[I][J] != -1 || cell[I][J] == '#' || cell[I][J] == 'm')continue;
- if(I >= n || J >= m || I < 0 || J < 0)continue;
- dist[I][J] = dist[i.x][i.y]+1;
- if(cell[I][J] == 'h')return dist[I][J];
- Qu.push(node(I, J));
- }
- }
- }
- void Do(){
- int t, cs = 0;
- sc(t);
- while(t--){
- sc(n); sc(m);
- for(int i = 0; i < n; i++)scS(cell[i]);
- int mx = -INT_MAX;
- for(int i = 0; i < n; i++){
- for(int j = 0; j < m; j++){
- if(cell[i][j] == 'a' || cell[i][j] == 'b' || cell[i][j] == 'c'){
- int x = bfs(i, j);
- mx = max(mx, x);
- }
- }
- }
- printf("Case %d: %d\n", ++cs, mx);
- }
- }
- int main(){
- ios_base::sync_with_stdio(0); cin.tie(0);
- #ifndef ONLINE_JUDGE
- ///freopen("inp","r",stdout);
- ///freopen("contest.txt","w",stdout);
- #endif
- Do();
- return 0;
- }
Subscribe to:
Posts (Atom)