本文整理汇总了C#中CFTraining.Helpers.FastScanner类的典型用法代码示例。如果您正苦于以下问题:C# FastScanner类的具体用法?C# FastScanner怎么用?C# FastScanner使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FastScanner类属于CFTraining.Helpers命名空间,在下文中一共展示了FastScanner类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public static void Run()
{
using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
{
int q = fs.NextInt();
long u, v, w;
List<Edge> path;
while (q-- > 0)
{
int t = fs.NextInt();
if (t == 1)
{
u = fs.NextLong();
v = fs.NextLong();
w = fs.NextLong();
path = GetPath(u, v);
foreach (var edge in path)
{
if (!costs.ContainsKey(edge)) costs.Add(edge, 0);
costs[edge] += w;
}
}
else
{
u = fs.NextLong();
v = fs.NextLong();
path = GetPath(u, v);
writer.WriteLine(GetCost(path));
}
}
}
}
示例2: Run
public static void Run()
{
using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
{
int n = fs.NextInt();
a = new int[n];
adjList = new LinkedList<Edge1>[n];
for (int i = 0; i < n; i++)
{
adjList[i] = new LinkedList<Edge1>();
a[i] = fs.NextInt();
}
for (int i = 0; i < n - 1; i++)
{
int p = fs.NextInt() - 1, c = fs.NextInt();
adjList[i + 1].AddLast(new Edge1 { v = p, w = c });
adjList[p].AddLast(new Edge1 { v = i + 1, w = c });
}
childNum = new int[n];
GetChildNum(0, new bool[n]);
long ans = VerticesToRemove(0, 0, new bool[n]);
writer.WriteLine(ans);
}
}
示例3: Run
public static void Run()
{
using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
{
int n = fs.NextInt();
int[] rows = new int[n], cols = new int[n];
for (int i = 0; i < n; i++)
{
string s = fs.ReadLine();
for (int j = 0; j < n; j++)
{
if (s[j] == 'C')
{
rows[i]++;
cols[j]++;
}
}
}
long ans = 0;
for (int i = 0; i < n; i++)
{
ans += (rows[i] * (rows[i] - 1)) / 2;
ans += (cols[i] * (cols[i] - 1)) / 2;
}
writer.WriteLine(ans);
}
}
示例4: Run
public static void Run()
{
using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
{
int t = fs.NextInt();
for (int i = 1; i <= t; i++)
{
long w = fs.NextLong();
if ((w & 1) == 0)
{
long m = 1;
while ((w & 1) == 0)
{
m <<= 1;
w >>= 1;
}
writer.WriteLine("Case " + i + ": " + w + " " + m);
}
else
{
writer.WriteLine("Case " + i + ": Impossible");
}
}
}
}
示例5: Run
public static void Run()
{
using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
{
int t = fs.NextInt();
Dictionary<string, int> count = new Dictionary<string, int>();
while (t-- > 0)
{
string[] cmd = fs.ReadLine().Split();
if (cmd[0] == "+")
{
long a = Convert.ToInt64(cmd[1]);
string pattern = NumToPattern(a);
if (!count.ContainsKey(pattern)) count.Add(pattern, 0);
count[pattern]++;
}
else if (cmd[0] == "-")
{
long a = Convert.ToInt64(cmd[1]);
string pattern = NumToPattern(a);
count[pattern]--;
}
else
{
string pattern = AppendZeros(cmd[1]);
writer.WriteLine(count.ContainsKey(pattern) ? count[pattern] : 0);
}
}
}
}
示例6: Run
public static void Run()
{
using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
{
int n = fs.NextInt();
int[] indices = new int[n];
long[] a = new long[n], b = new long[n];
for (int i = 0; i < n; i++)
{
int r = fs.NextInt(), h = fs.NextInt();
a[i] = (long)r * r * h;
indices[i] = i;
}
Array.Copy(a, b, n);
Array.Sort(b);
for (int i = 0; i < n; i++)
{
indices[i] = findValue(b, 0, n - 1, a[i]);
}
MaxSegmentTree tree = new MaxSegmentTree(new long[n]);
for (int i = 0; i < n; i++)
{
int index = indices[i];
long value = tree.QueryMax(0, indices[i] - 1) + a[i];
tree.Update(indices[i], indices[i], value);
}
writer.WriteLine((tree.QueryMax(0, n - 1) * Math.PI).ToString().Replace(',', '.'));
}
}
示例7: Run
public static void Run()
{
using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
{
int n = fs.NextInt();
LinkedList<int>[] adjList = new LinkedList<int>[n];
for (int i = 0; i < n; i++)
{
adjList[i] = new LinkedList<int>();
}
for (int i = 0; i < n; i++)
{
int v = fs.NextInt() - 1;
if (v != i) adjList[i].AddLast(v);
if (i > 0)
{
adjList[i].AddLast(i - 1);
adjList[i - 1].AddLast(i);
}
}
int[] dist = Enumerable.Repeat(int.MaxValue, n).ToArray();
RunDijkstra(adjList, dist);
foreach (int x in dist)
{
writer.Write(x + " ");
}
}
}
示例8: Run
public static void Run()
{
using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
{
string str = fs.ReadLine();
List<int> list = new List<int>(str.Length);
int first = -1;
for (int i = 0; i < str.Length; i++)
{
if (str[i] == 'F')
{
if (first == -1 && list.Count != i)
{
first = list.Count;
}
list.Add(i);
}
}
if (list.Count == 0 || list.Count == str.Length || first == -1)
{
writer.WriteLine(0);
return;
}
int t = 0;
for (int i = first + 1; i < list.Count; i++)
{
t = Math.Max(0, t - list[i] + list[i - 1] + 2);
}
writer.WriteLine(t + list.Last() - list.Count + 1);
}
}
示例9: Run
public static void Run()
{
using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
{
int n = fs.NextInt(), a = fs.NextInt(), b = fs.NextInt();
int[] p = new int[n];
Dictionary<int, int> pos = new Dictionary<int, int>();
Node[] nodes = new Node[n];
for (int i = 0; i < n; i++)
{
p[i] = fs.NextInt();
nodes[i] = new Node { Value = p[i] };
pos.Add(p[i], i);
}
for (int i = 0; i < n; i++)
{
int adiff = a - nodes[i].Value;
int bdiff = b - nodes[i].Value;
if (pos.ContainsKey(adiff))
{
nodes[i].Adiff = nodes[pos[adiff]];
nodes[pos[adiff]].Adiff = nodes[i];
}
if (pos.ContainsKey(bdiff) && a != b)
{
nodes[i].Bdiff = nodes[pos[bdiff]];
nodes[pos[bdiff]].Bdiff = nodes[i];
}
}
int[] ans = Enumerable.Repeat(-1, n).ToArray();
for (int i = 0; i < n; i++)
{
Node current = nodes[i];
if (!Traverse(nodes, current, pos, ans))
{
writer.WriteLine("NO");
return;
}
}
for (int i = 0; i < n; i++)
{
Node current = nodes[i];
if (current.Adiff == current || current.Bdiff == current)
{
if (current.Adiff == current && current.Bdiff == null) ans[i] = 0;
else if (current.Adiff == current && current.Bdiff != null) current.Adiff = null;
else if (current.Bdiff == current && current.Adiff == null) ans[i] = 1;
else if (current.Bdiff == current && current.Adiff != null) current.Bdiff = null;
}
Traverse(nodes, current, pos, ans);
}
writer.WriteLine("YES");
for (int i = 0; i < n; i++)
{
writer.Write(ans[i] + " ");
}
}
}
示例10: Run
public static void Run()
{
using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
{
long x1 = fs.NextInt(), y1 = fs.NextInt();
long x2 = fs.NextInt(), y2 = fs.NextInt();
int n = fs.NextInt();
Line original = new Line
{
A = y1 - y2,
B = x2 - x1,
C = x1 * y2 - x2 * y1
};
long minX = Math.Min(x1, x2), maxX = Math.Max(x1, x2);
long minY = Math.Min(y1, y2), maxY = Math.Max(y1, y2);
int count = 0;
for (int i = 0; i < n; i++)
{
Line line = new Line { A = fs.NextInt(), B = fs.NextInt(), C = fs.NextInt() };
double[] cross = GetIntersection(original, line);
if (cross[0] >= minX && cross[0] <= maxX &&
cross[1] >= minY && cross[1] <= maxY) count++;
}
writer.WriteLine(count);
}
}
示例11: Run
public static void Run()
{
using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
{
N = fs.NextInt();
AdjList = new LinkedList<int>[N];
for (int i = 0; i < N; i++)
{
AdjList[i] = new LinkedList<int>();
}
for (int i = 0; i < N - 1; i++)
{
int u = fs.NextInt() - 1, v = fs.NextInt() - 1;
AdjList[u].AddLast(v);
AdjList[v].AddLast(u);
}
int max = 0;
foreach (int v in AdjList[0])
{
List<int> times = new List<int>();
DFS(times, v, 0, 1);
int[] temp = times.OrderBy(i => i).ToArray();
for (int i = 1; i < temp.Length; i++)
{
if (temp[i] <= temp[i - 1]) temp[i] = temp[i - 1] + 1;
}
max = Math.Max(max, temp[temp.Length - 1]);
}
writer.WriteLine(max);
}
}
示例12: Run
public static void Run()
{
using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
{
int n = fs.NextInt();
Segment[] segms = new Segment[n];
int[] ans = new int[n];
for (int i = 0; i < n; i++)
{
segms[i] = new Segment { Id = i, Left = fs.NextInt(), Right = fs.NextInt() };
}
segms = segms.OrderBy(s => s.Left).ToArray();
Segment[] t = segms.OrderBy(s => s.Right).ToArray();
int[] ind = new int[n];
for (int i = 0; i < n; i++)
{
ind[i] = findItem(t, 0, n - 1, segms[i].Right);
}
SegmentTree tree = new SegmentTree(new int[n]);
for (int i = n - 1; i >= 0; i--)
{
ans[segms[i].Id] = tree.QuerySum(0, ind[i] - 1);
tree.Update(ind[i], ind[i], 1);
}
for (int i = 0; i < n; i++)
{
writer.WriteLine(ans[i]);
}
}
}
示例13: Run
public static void Run()
{
using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
{
int n = fs.NextInt();
int[] a = new int[n];
List<int[]> d = new List<int[]>();
string s = fs.ReadLine();
for (int i = 0; i < n; i++)
{
a[i] = int.Parse("" + s[i]);
if (i > 0) d.Add(GetDiff(a[i - 1], a[i]));
}
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 3; j++)
{
if (digits[i, j] == a[0]) continue;
if (digits[i, j] != -1 && IsValid(i, j, d))
{
writer.WriteLine("NO");
return;
}
}
}
writer.WriteLine("YES");
}
}
示例14: Run
public static void Run()
{
using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
{
int n = fs.NextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++)
{
a[i] = fs.NextInt();
}
for (int i = 0; i < n; i++)
{
for (int j = 1; j < n - i; j++)
{
if (a[j] < a[j - 1])
{
int t = a[j];
a[j] = a[j - 1];
a[j - 1] = t;
writer.WriteLine(j + " " + (j + 1));
}
}
}
}
}
示例15: Run
public static void Run()
{
using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
{
int n = fs.NextInt();
int[] male = new int[367], fem = new int[367];
for (int i = 0; i < n; i++)
{
string[] line = fs.ReadLine().Split(' ');
if (line[0] == "M")
{
int l = Convert.ToInt32(line[1]), r = Convert.ToInt32(line[2]);
for (int j = l; j <= r; j++) male[j]++;
}
else if (line[0] == "F")
{
int l = Convert.ToInt32(line[1]), r = Convert.ToInt32(line[2]);
for (int j = l; j <= r; j++) fem[j]++;
}
}
int ans = 0;
for (int i = 1; i < 367; i++)
{
ans = Math.Max(ans, Math.Min(male[i], fem[i]) * 2);
}
writer.WriteLine(ans);
}
}