public Program(string inputFile, string outputFile) { io = new IOHelper(inputFile, outputFile, Encoding.Default); sizeOfEach = new List <int>(); sizeOfEach.Add(0); n = io.NextInt(); m = io.NextInt(); k = io.NextInt(); map = new string[n]; foreach (int i in E.Range(0, n)) { map[i] = io.NextToken(); } vis = new int[n, m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (map[i][j] != '*' && vis[i, j] == 0) { sizeOfEach.Add(bfs(new Point(i, j))); } } } for (; k-- > 0;) { int xi = io.NextInt(); int yi = io.NextInt(); --xi; --yi; io.WriteLine(sizeOfEach[vis[xi, yi]]); } io.Dispose(); }
public Program(string inputFile, string outputFile) { io = new IOHelper(inputFile, outputFile, Encoding.Default); //n==6 -- 1 3 5 5 3 1 + 2 4 6 4 2 + 6 //n==7 -- 1 3 5 7 5 3 1 + 2 4 6 6 4 2 + 7 int n = io.NextInt(); for (int i = 1; i <= n; i += 2) { io.Write(i + " "); } for (int i = n - (n % 2 == 0 ? 1 : 2); i >= 1; i -= 2) { io.Write(i + " "); } for (int i = 2; i <= n; i += 2) { io.Write(i + " "); } for (int i = n - (n % 2 == 0 ? 2 : 1); i >= 1; i -= 2) { io.Write(i + " "); } io.WriteLine(n); io.Dispose(); }
public Program(string inputFile, string outputFile) { io = new IOHelper(inputFile, outputFile, Encoding.Default); m = io.NextInt(); d = io.NextInt(); string a = io.NextToken(), b = io.NextToken(); BigInteger tmp = BigInteger.Parse(a); tmp -= 1; a = tmp.ToString(); if (a.Length < b.Length) { a = "0" + a; } long ans = calc(b) - calc(a); ans %= mod; if (ans < 0) { ans += mod; } io.WriteLine(ans); io.Dispose(); }
public Program(string inputFile, string outputFile) { io = new IOHelper(inputFile, outputFile, Encoding.Default); SortedSet <int> s = new SortedSet <int>(); n = io.NextInt(); int[] ans = new int[n]; a = new int[2 * n + 5]; Record[] rec = new Record[n]; for (int i = 0; i < n; i++) { rec[i] = new Record(i, io.NextInt(), io.NextInt()); if (!s.Contains(rec[i].x)) { s.Add(rec[i].x); } if (!s.Contains(rec[i].y)) { s.Add(rec[i].y); } } Array.Sort(rec); var it = s.GetEnumerator(); var s2 = new SortedDictionary <int, int>(); int id = 1; while (it.MoveNext()) { s2.Add(it.Current, id++); } for (int i = 0; i < n; i++) { rec[i].x = s2[rec[i].x]; rec[i].y = s2[rec[i].y]; } for (int i = 0; i < n; i++) { ans[rec[i].id] = sum(rec[i].y); add(rec[i].y, 1); } for (int i = 0; i < n; i++) { io.WriteLine(ans[i]); } io.Dispose(); }
public Program(string inputFile, string outputFile) { io = new IOHelper(inputFile, outputFile, Encoding.Default); int n, k; n = io.NextInt(); k = io.NextInt(); int[] d = new int[n + 1]; for (int i = 1; i <= n; i++) { d[i] = io.NextInt(); } Dictionary <int, int> dict = new Dictionary <int, int>(); int besthead = 1, besttail = 1; int h = 1; dict[d[1]] = 1; for (int i = 2; i <= n; i++) { if (!dict.ContainsKey(d[i])) { dict[d[i]] = 1; while (dict.Count > k) { --dict[d[h]]; if (dict[d[h]] == 0) { dict.Remove(d[h]); } h++; } } else { ++dict[d[i]]; } if (i - h > besttail - besthead) { besttail = i; besthead = h; } } io.WriteLine(besthead + " " + besttail); io.Dispose(); }
public Program(string inputFile, string outputFile) { io = new IOHelper(inputFile, outputFile, Encoding.Default); int n, k; n = io.NextInt(); k = io.NextInt(); int[] d = new int[n+1]; for (int i = 1; i <= n; i++) d[i] = io.NextInt(); Dictionary<int, int> dict = new Dictionary<int, int>(); int besthead=1, besttail=1; int h=1; dict[d[1]]=1; for (int i = 2; i <= n;i++ ) { if (!dict.ContainsKey(d[i])) { dict[d[i]] = 1; while (dict.Count > k) { --dict[d[h]]; if (dict[d[h]] == 0) { dict.Remove(d[h]); } h++; } } else ++dict[d[i]]; if (i - h > besttail - besthead) { besttail = i; besthead = h; } } io.WriteLine(besthead + " " + besttail); io.Dispose(); }
public Program(string inputFile, string outputFile) { io = new IOHelper(inputFile, outputFile, Encoding.Default); //直接思路:枚举1~m的lcm,对每个lcm枚举约数,然后约数的bin里都要,复杂度msqrt(m) //那么现在反转,枚举约数,再枚举这个数是哪些可能的lcm值的约数 //根据调和级数公式,n/1+n/2+n/3+...n/n=nlogn int n=io.NextInt(),m = io.NextInt(); List<int>[] bin = new List<int>[m + 1]; for (int i = 0; i <= m; i++) bin[i] = new List<int>(); for (int i = 1; i <= n; i++) { int x = io.NextInt(); if (x <= m) bin[x].Add(i); } int[] cnt = new int[m + 1]; for (int i = 1; i <= m; i++) { if (bin[i].Count == 0) continue; for (int j = i; j <= m; j += i) { cnt[j] += bin[i].Count; } } int maxElement=cnt.Max(); for (int i = 1; i <= m; i++) { if (cnt[i] == maxElement) { io.WriteLine(i+" "+maxElement); List<int> ans=new List<int>(); for (int j = 1; j <= Math.Sqrt(i); j++) { if (i % j == 0) { ans.AddRange(bin[j]); if (j * j != i) ans.AddRange(bin[i / j]); } } ans.Sort(); foreach (int k in ans) { io.Write(k + " "); } break; } } io.Dispose(); }
public Program(string inputFile, string outputFile) { io = new IOHelper(inputFile, outputFile, Encoding.Default); //n==6 -- 1 3 5 5 3 1 + 2 4 6 4 2 + 6 //n==7 -- 1 3 5 7 5 3 1 + 2 4 6 6 4 2 + 7 int n = io.NextInt(); for (int i = 1; i <= n; i += 2) io.Write(i + " "); for (int i = n - (n % 2 == 0 ? 1 : 2); i >= 1; i -= 2) io.Write(i + " "); for (int i = 2; i <= n; i += 2) io.Write(i + " "); for (int i = n - (n % 2 == 0 ? 2 : 1); i >= 1; i -= 2) io.Write(i + " "); io.WriteLine(n); io.Dispose(); }
public Program(string inputFile, string outputFile) { io = new IOHelper(inputFile, outputFile, Encoding.Default); //直接思路:枚举1~m的lcm,对每个lcm枚举约数,然后约数的bin里都要,复杂度msqrt(m) //那么现在反转,枚举约数,再枚举这个数是哪些可能的lcm值的约数 //根据调和级数公式,n/1+n/2+n/3+...n/n=nlogn int n = io.NextInt(), m = io.NextInt(); List <int>[] bin = new List <int> [m + 1]; for (int i = 0; i <= m; i++) { bin[i] = new List <int>(); } for (int i = 1; i <= n; i++) { int x = io.NextInt(); if (x <= m) { bin[x].Add(i); } } int[] cnt = new int[m + 1]; for (int i = 1; i <= m; i++) { if (bin[i].Count == 0) { continue; } for (int j = i; j <= m; j += i) { cnt[j] += bin[i].Count; } } int maxElement = cnt.Max(); for (int i = 1; i <= m; i++) { if (cnt[i] == maxElement) { io.WriteLine(i + " " + maxElement); List <int> ans = new List <int>(); for (int j = 1; j <= Math.Sqrt(i); j++) { if (i % j == 0) { ans.AddRange(bin[j]); if (j * j != i) { ans.AddRange(bin[i / j]); } } } ans.Sort(); foreach (int k in ans) { io.Write(k + " "); } break; } } io.Dispose(); }
public Program(string inputFile, string outputFile) { io = new IOHelper(inputFile, outputFile, Encoding.Default); sizeOfEach = new List<int>(); sizeOfEach.Add(0); n = io.NextInt(); m = io.NextInt(); k = io.NextInt(); map = new string[n]; foreach (int i in E.Range(0, n)) { map[i] = io.NextToken(); } vis = new int[n, m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (map[i][j]!='*'&&vis[i, j] == 0) { sizeOfEach.Add(bfs(new Point(i, j))); } } } for (; k-- > 0; ) { int xi = io.NextInt(); int yi = io.NextInt(); --xi; --yi; io.WriteLine(sizeOfEach[vis[xi, yi]]); } io.Dispose(); }
public Program(string inputFile, string outputFile) { io = new IOHelper(inputFile, outputFile, Encoding.Default); m = io.NextInt(); d = io.NextInt(); string a = io.NextToken(), b = io.NextToken(); BigInteger tmp = BigInteger.Parse(a); tmp -= 1; a = tmp.ToString(); if (a.Length < b.Length) a = "0" + a; long ans = calc(b) - calc(a); ans %= mod; if (ans < 0) ans += mod; io.WriteLine(ans); io.Dispose(); }